I am making a little weather app using the Yahoo api. This api gives me an XML file back. My problem is now how I can parse this file ? Here is my code that I have so far.
AFXMLRequestOperation *operation = [AFXMLRequestOperation XMLParserRequestOperationWithRequest:request success:^(NSURLRequest *request, NSHTTPURLResponse *response, NSXMLParser *XMLParser) {
NSLog(@"success");
XMLParser.delegate = self;
[XMLParser parse];
NSLog(@"xmlParser is %@",XMLParser);
} failure:^(NSURLRequest *request, NSHTTPURLResponse *response, NSError *error, NSXMLParser *XMLParser) {
NSLog(@"failure with error %@",error);
}];
You can find the XML file over here.
Hope that anybody can help me
If you are looking to parse XMLs using NSXMLParser you'll need to have a class that implements the NSXMLParserDelegate. You can use your ViewController for this:
Then using the SAX methods provided by this protocol you can parse this XML when you run
[XMLParser parse]
. Here is an example for your xml:Also to get AFNetworking to support the RSS xml you are using I had to add "application/rss+xml" to the acceptableContentTypes following the instructions from this site: http://www.suushmedia.com/simple-rss-reader-with-afnetworking/
Hope this helps
Better Solution: I found here