How do I use touchXML to parse this XML? I want to store all the attributes as key/value pairs in a dictionary.
<Player PlayerName="Padraig HARRINGTON" CurrentPosition="1" CurrentRank="1"
Country="IRL" NumberOfHolesPlayed="18" ParRelativeScore="+3">
<RoundScore RoundNumber="1" Score="74" />
<RoundScore RoundNumber="2" Score="68" />
<RoundScore RoundNumber="3" Score="72" />
<RoundScore RoundNumber="4" Score="69" />
</Player>
<Player PlayerName="Ian POULTER" CurrentPosition="2" CurrentRank="2" Country="ENG"
NumberOfHolesPlayed="18" ParRelativeScore="+7">
<RoundScore RoundNumber="1" Score="72" />
<RoundScore RoundNumber="2" Score="71" />
<RoundScore RoundNumber="3" Score="75" />
<RoundScore RoundNumber="4" Score="69" />
</Player>
<Player PlayerName="Henrik STENSON" CurrentPosition="3" CurrentRank="T3" Country="SWE"
NumberOfHolesPlayed="18" ParRelativeScore="+9">
<RoundScore RoundNumber="1" Score="76" />
<RoundScore RoundNumber="2" Score="72" />
<RoundScore RoundNumber="3" Score="70" />
<RoundScore RoundNumber="4" Score="71" />
</Player>
I have no problem is the XML is formatted like so:
<Player>
<Country>UK</Country>
<NumberOfHolesPlayed>12</NumberOfHolesPlayed>
...
...
But I'm not sure what to do when dealing with attributes...
How can you get attributes with touchXML? In particular if a node has a subnode that also has attributes..
As per the first example XML file. In the first XML example I managed to get the Player attributes but not the child nodes 'RoundScore' attributes.
Would love a helping hand..
Thanks,
Dan
Use TBXML, its much easier and faster on working with XML files. Nice documentation also. Your problem with Attributes is easier solved here. http://www.tbxml.co.uk/TBXML/TBXML_Free.html
For more information visit this post . I have given complete brief about it.
Yep ! solved your problem.
see, following code. Hope you understand. It's working for your requirement. I also have added - NSLog - Result - parsed.
I found out that you have to check the child nodes are CXElements. Sometimes they're CXMLNodes and these don't have attribute properties.