I'm trying to parse a Stack Overflow RSS feed of a specific question: http://stackoverflow.com/feeds/question/2110875
For this I'm using the TouchXML library. There seems to be a problem in the following code:
CXMLDocument *parser = [[CXMLDocument alloc] initWithData:sourceData options:0 error:nil];
NSArray *allEntries = [parser nodesForXPath:@"//entry" error:nil];
NSLog(@"Found entries: %d",[allEntries count]); //Returns 0
The NSLog statement should return the count of all entries in the feed. In this case it should be '3', problem is that it returns 0.
I found that this piece of code does work:
CXMLDocument *preParser = [[CXMLDocument alloc] initWithData:sourceData options:0 error:nil];
NSString *sourceStringUTF8 = [preParser XMLString];
[preParser release];
CXMLDocument *parser = [[CXMLDocument alloc] initWithData:[sourceStringUTF8 dataUsingEncoding:NSUTF8StringEncoding] options:0 error:nil];
NSArray *allEntries = [parser nodesForXPath:@"//entry" error:nil];
NSLog(@"Found entries: %d",[allEntries count]); //Returns 3, which is ok
But using this seems hacky (it probably is) and introduces a few other sporadic bugs.
As far as I know the Xpath expression is correct. I've checked it using this page as well.
Can anyone help me with this problem, or point me in the right direction.
Thanks.