By endy


2010-11-15 05:36:30 8 Comments

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.

5 comments

@onmyway133 2014-06-11 07:03:22

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

@tadija 2014-10-17 12:03:36

I made this new simple and lightweight XML parser for iOS in Swift - AEXML

You can use it to read XML data like this:

let someValue = xmlDocument["element"]["child"]["anotherChild"].value

or you can use it to build XML string like this:

let document = AEXMLDocument()
let element = document.addChild("element")
element.addChild("child")
document.xmlString // returns XML string of the entire document structure

I hope it will be useful for someone.

@Shan 2012-10-29 07:39:41

As you have requirement for medium sized XML

TinyXML could be an good choice for medium sized documents if you already have experience with the API and are comfortable with C as it ports quite easily over to the iPhone.

For More information you can go through this link

@Daniel Amitay 2010-11-15 06:26:01

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.

@Cameron 2011-07-28 15:21:10

Some of the stuff in the article is getting outdated, but overall still very helpful (just posting so people can see this answer is still valid as of the end of July)

@Eonil 2011-12-19 08:09:40

Note. KissXML moved to Github and still actively being updated. github.com/robbiehanson/KissXML

@Jan S. 2012-11-23 04:34:29

In case anybody wants to re-run the tests with updated parsers: github.com/jansanz/iOSXMLPerformance (I have also included 2 more that weren't originally in the test).

@Gajendra K Chauhan 2014-07-01 03:47:41

TouchXML is also good.

@ZaBlanc 2011-09-27 14:41:05

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!

@user7865437 2011-12-01 21:37:04

RaptureXML is wicked!!

@sudo rm -rf 2011-12-09 23:04:26

Oh man, that's awesome! Thanks for sharing this!

@endy 2011-12-14 19:59:41

I have a new project to work on this year. This looks amazing.

@Steve HHH 2012-02-22 03:58:59

RaptureXML is magnificent. Very easy to set up and use.

@dhaya 2013-04-22 10:08:42

even rapturexml sample is not working..

Related Questions

Sponsored Content

15 Answered Questions

[SOLVED] How do I parse XML in Python?

  • 2009-12-16 05:09:24
  • randombits
  • 1162305 View
  • 935 Score
  • 15 Answer
  • Tags:   python xml

9 Answered Questions

[SOLVED] What characters do I need to escape in XML documents?

6 Answered Questions

[SOLVED] How do I comment out a block of tags in XML?

  • 2010-05-03 10:31:24
  • Jonas
  • 1706414 View
  • 774 Score
  • 6 Answer
  • Tags:   xml comments

30 Answered Questions

[SOLVED] How do you parse and process HTML/XML in PHP?

12 Answered Questions

[SOLVED] What does <![CDATA[]]> in XML mean?

  • 2010-05-06 20:20:50
  • dontWatchMyProfile
  • 1182188 View
  • 966 Score
  • 12 Answer
  • Tags:   xml cdata

2 Answered Questions

[SOLVED] XML parsing - iPhone

Sponsored Content