Hello guys I'm looking for a way on the iPhone to parse an XML document using DOM. I have been using SAX with NSXMLParser but now I really want a DOM tree (or anything that can quickly translate the XML document into an NSDictionary)
Thanks for any help

- 8,618
- 7
- 49
- 79
3 Answers
If you want to use libxml2
with an Objective-C front without SAX events, take a look at this useful set of wrapper functions.
You issue an XPath query to your XML document object and get back Foundation class objects: NSArray
, NSString
, and NSDictionary
, e.g.:
NSArray *queriedBuckets = PerformXMLXPathQuery(responseData, @"//*[local-name()='Buckets']/*[local-name()='Bucket']");
These functions help merge the speed of libxml2
with the readability and usability of Objective-C code.

- 95,983
- 54
- 240
- 345
Unfortunately, NSXMLDocument
(which does what you're asking) does not exist on the iPhone. You may have to roll your own parser using libxml2
, or try something like TouchXML or KissXML.

- 86,735
- 21
- 136
- 138

- 242,470
- 58
- 448
- 498
-
1TouchXML doesn't support ARC. KissXML supports ARC. – Sam Feb 27 '13 at 13:32
I suggest looking at the Google Data API for Objective-C (iPhone) at http://code.google.com/p/gdata-objectivec-client/
In particular, look at these files which define the GDataXMLNode class:
http://gdata-objectivec-client.googlecode.com/svn/trunk/Source/XMLSupport/

- 41
- 2