Reading XML File from Server
I'm currently parsing an XML file that resides in my bundle using NSXMLParser with the following line:
NSURL *xmlURL = [NSURL fileURLWithPath:[[NSBundle mainBundle] pa开发者_高级运维thForResource:@"XMLFileName" ofType:@"xml"]];
But I want to put the same file on my server instead. I can't find an example of how to call the same file from my server. Any help is appreciated. lq
NSURL
has several methods for creating URLs, one of which is -URLWithString:
; like so:
NSURL *xmlURL = [NSURL URLWithString:@"http://example.com/example.xml"];
That URL can be passed directly to NSXMLParser
; but you might want to do so in a secondary thread.
If you want to HTTP GET the file from your server then you should look at NSURLConnection
. It allows you to do synchronous or asynchronous HTTP requests.
精彩评论