开发者

libxml2 example (with wrapper)

I am using the XML parser libxml2 with wrap开发者_JAVA技巧per as given on the page http://cocoawithlove.com/2008/10/using-libxml2-for-parsing-and-xpath.html

But i am not sure if I am using correctly and am getting errors (parsing,etc)

So could someone please provide me a complete example which i can refer and get an idea if I am doing something incorrectly.

thanks a lot for all your help in advance.


I'm using this methods too, to parse xml and html files. For example to parse rss xml:

//add xml source
NSURL *url = [NSURL URLWithString:@"http://feeds.bbci.co.uk/news/rss.xml?edition=int"];     
NSData *xmlData = [NSData dataWithContentsOfURL:url];

//parse the whole file with all tags
NSArray *rssFeedArray = PerformXMLXPathQuery(xmlData, @"//*");
NSLog(@"rssFeedArray: %@", rssFeedArray);

//* - query means the parser will go through all tags of the file. Then log the array to see the whole structure of xml.

Whith '/rss/channel/item' query you will only get the item tags element's, (or to get only the first item use '/rss/channel/item[1]').

in this case because of the bbc feed structure you can catch each item title at

[[[[rssFeedArray objectAtIndex:i] valueForKey:@"nodeChildArray"] objectAtIndex:0] valueForKey:@"nodeContent"]]

and description at

[[[[rssFeedArray objectAtIndex:i] valueForKey:@"nodeChildArray"] objectAtIndex:1]valueForKey:@"nodeContent"]]

and go on and on.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜