Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Choosing the right IOS XML parser [closed]

Tags:

parsing

ios

xml

sdk

There are a million different XML parsers for the iPhone. I have a medium sized XML file that contains alot of duplicate tags (at different points in the hierarchy). I was thinking about TBXML but I was concerned about its lack of XPath support. For instance lets say my XML file looked like this.

<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>

Basically my requirements are that I need to be able to extract that cdata. And know whether it is the blog author a comment author.

like image 367
endy Avatar asked Nov 15 '10 05:11

endy


3 Answers

Best comparison I've seen on the subject:

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

The difference between the slowest and fastest parsers in his case was a factor of 2. Depending on your feature requirements, there are definitely parsers that can cut your parsing time in half.

like image 193
Daniel Amitay Avatar answered Oct 22 '22 15:10

Daniel Amitay


Check out RaptureXML. It's not official XPath behavior, but it's pretty close. Your query would be:

[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);
    }
}];

UPDATE: RaptureXML now supports XPath!

like image 36
ZaBlanc Avatar answered Oct 22 '22 14:10

ZaBlanc


You should look at these libraries, in order :)

  1. Ono, powered by libxml2
  2. XMLDictionary
  3. RaptureXML

Ono has the the cool AFOnoResponseSerializer which can be integrated with AFNetworking

like image 22
onmyway133 Avatar answered Oct 22 '22 14:10

onmyway133