SMXMLDocument 是一个非常方便的轻量级 XML 解析器,适用于 iOS。
简要来说
// create a new SMXMLDocument with the contents of sample.xml
SMXMLDocument *document = [SMXMLDocument documentWithData:data error:&error];
// Pull out the <books> node
SMXMLElement *books = [document.root childNamed:@"books"];
// Look through <books> children of type <book>
for (SMXMLElement *book in [books childrenNamed:@"book"]) {
// demonstrate common cases of extracting XML data
NSString *isbn = [book attributeNamed:@"isbn"]; // XML attribute
NSString *title = [book valueWithPath:@"title"]; // child node value
// show off some KVC magic
NSArray *authors = [[book childNamed:@"authors"].children valueForKey:@"value"];
// do interesting things...
}
更多详细信息请参考博客文章:http://nfarina.com/post/2843708636/a-lightweight-xml-parser-for-ios
如果你的项目禁用了 自动引用计数 (ARC),请尝试 master_no_arc 分支。