Getting an XML file from URL to NSData object?

Assuming it's UTF-8 data. If it's local (i.e. Inside the bundle) something like: NSError *error; NSString* contents = NSString stringWithContentsOfFile:PATHTOLOCALFILE encoding:NSUTF8StringEncoding error:&error; NSData* xmlData = contents dataUsingEncoding:NSUTF8StringEncoding If it's on a remote site, something like this should do it.

Note that it's synchronous. If you need asynchronous loading, then you'll have to make your own networking or use something like ASIHTTPConnection to download the file first NSError *error; NSString* contents = NSString stringWithContentsOfUrl:NSURL URLWithString:URLOFXMLFILE encoding:NSUTF8StringEncoding error:&error; NSData* xmlData = contents dataUsingEncoding:NSUTF8StringEncoding.

Assuming it's UTF-8 data. If it's local (i.e. Inside the bundle) something like: NSError *error; NSString* contents = NSString stringWithContentsOfFile:PATHTOLOCALFILE encoding:NSUTF8StringEncoding error:&error; NSData* xmlData = contents dataUsingEncoding:NSUTF8StringEncoding; If it's on a remote site, something like this should do it.

Note that it's synchronous. If you need asynchronous loading, then you'll have to make your own networking or use something like ASIHTTPConnection to download the file first. NSError *error; NSString* contents = NSString stringWithContentsOfUrl:NSURL URLWithString:URLOFXMLFILE encoding:NSUTF8StringEncoding error:&error; NSData* xmlData = contents dataUsingEncoding:NSUTF8StringEncoding.

You can call NSData's - (id)initWithContentsOfURL:(NSURL *)aURL routine. More info here: developer.apple.com/documentation/Cocoa/....

If you need asynchronous loading, then you'll have to make your own networking or use something like ASIHTTPConnection to download the file first.

I cant really gove you an answer,but what I can give you is a way to a solution, that is you have to find the anglde that you relate to or peaks your interest. A good paper is one that people get drawn into because it reaches them ln some way.As for me WW11 to me, I think of the holocaust and the effect it had on the survivors, their families and those who stood by and did nothing until it was too late.

Related Questions