Skip to content

Instantly share code, notes, and snippets.

@krhoyt
Last active December 27, 2015 16:59
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save krhoyt/7359148 to your computer and use it in GitHub Desktop.
Save krhoyt/7359148 to your computer and use it in GitHub Desktop.
Load an XML file, parse the contents, and find a specific node.
- ( void ) loadAndParseXMLFile : ( NSString * ) url
{
NSArray * items;
NSArray * query;
NSError * error;
NSXMLDocument * doc;
NSXMLNode * item;
// XPath for the win!
doc = [[NSXMLDocument alloc] initWithContentsOfURL : [NSURL URLWithString : url] options : ( NSXMLNodePreserveWhitespace | NSXMLNodePreserveCDATA ) error : &error];
items = [doc nodesForXPath:@"//item" error : &error];
NSLog( @"Found %lu RSS items.", [items count] );
for( item in items )
{
query = [item nodesForXPath : @"title" error : &error];
NSLog( @"%@", [[query objectAtIndex: 0] objectValue]);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment