Firstly, the XML file is malformed, the last two closing tags channel,rss
are missing the /
.NSXMLDocument
will not parse that XML.
Assuming that was a typo (if not, this approach will not work at all), this code may get you started:
NSError *error=nil;
NSXMLDocument *xmlDOC=[[NSXMLDocument alloc]
initWithContentsOfURL:[NSURL fileURLWithPath:xmlPath]
options:NSXMLNodeOptionsNone
error:&error
];
if(!xmlDOC)
{
NSLog(@"Error opening '%@': %@",xmlPath,error);
return;
}
NSXMLElement *rootElement=[xmlDOC rootElement];
NSArray *items=[rootElement nodesForXPath:@"channel/item" error:&error];
if(!items)
{
NSLog(@"Can't get 'channel/item': %@",error);
return;
}
for(NSXMLElement *item in items)
{
NSLog(@"title: %@",[[[item nodesForXPath:@"title" error:&error]firstObject]stringValue]);
NSLog(@"link: %@",[[[item nodesForXPath:@"link" error:&error]firstObject]stringValue]);
NSLog(@"description: %@",[[[item nodesForXPath:@"description" error:&error]firstObject]stringValue]);
}