Last active
December 27, 2015 16:59
-
-
Save krhoyt/7359148 to your computer and use it in GitHub Desktop.
Load an XML file, parse the contents, and find a specific node.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
- ( 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