选择正确的IOS XML解析器

end*_*ndy 40 xml sdk parsing ios

iPhone有一百万种不同的XML解析器.我有一个中等大小的XML文件,其中包含许多重复标记(在层次结构中的不同点).我在考虑TBXML,但我担心它缺乏XPath支持.例如,假设我的XML文件看起来像这样.

<blog>
   <author> foo1 </author>
   <comments>

       <comment>
            <text>
                <![CDATA[ HTML code that must be extracted ]]>
            </text>
            <author>foo2</author>
       </comment>

       <comment>
          <text>
              <![CDATA[ Here is another post ]]> 
          </text>
          <author>foo1</author>
      </comment>

   </comments>
</blog>
Run Code Online (Sandbox Code Playgroud)

基本上我的要求是我需要能够提取该cdata.并且知道它是否是博客作者的评论作者.

Dan*_*tay 52

我在这个问题上看到的最佳比较:

http://www.raywenderlich.com/553/how-to-chose-the-best-xml-parser-for-your-iphone-project

在他的情况下,最慢和最快的解析器之间的差异是2.根据您的功能要求,肯定有解析器可以将您的解析时间缩短一半.


ZaB*_*anc 31

查看RaptureXML.这不是官方的XPath行为,但它非常接近.您的查询将是:

[rxml iterate:@"comments.comment" with: ^(RXMLElement *e) {
    if ([[e child:@"author"].text isEqualToString:@"foo1"]) {
        NSLog(@"Blog Text is %@.", e.text);
    } else {
        NSLog(@"Comment Text is %@.", e.text);
    }
}];
Run Code Online (Sandbox Code Playgroud)

更新:RaptureXML现在支持XPath!

  • RaptureXML是邪恶的! (4认同)