Hi everyone,
I've been wondering if there's a way to parse XML in Objective C as easily as parsing with SimpleXML in PHP.
The only existing methods I know are the following:
Use of NSXMLParser and create a delegate to handle the events triggered upon encountering XML elements, values, etc...
Use of libxml2 based framework such as TouchXML, to make use of the XPath to easily query nodes in the XML file.
I'm not sure if there are any other approach to parsing XML in Objective C for iPhone.
Thanks in advance for the help! :)
Cheers! Oonoo
Update: SimpleXML sample
In case unfamiliar with SimpleXML, it can be as easy as this:
$xml = simplexml_load_string($xmlfilecontents);
echo $xml->user->name; //for this example code, im not traversing through all the user elements
Given that the xmlfilecontents is an xml file content in string type, containing users elements() with child :
<users>
<user><name>john</name></user>
<user><name>jane</name></user>
</users>
It simply loads the xml and instantiate automatically an object that captures all the data in the xml file. Accessing the data is a straightforward call like $xml->element->attr