Hello Everyone,
I need to create a javascript array or object from an XML file that is structured as follows:
<ITEMS>
<TXT id="8" typ="1" pid="7" x="708" y="216" fcol="6777213" txt="sometext" hcmd="0" click="1"/>
<TXT id="9" typ="1" pid="2" x="708" y="144" fcol="1231341" txt="some other text" hcmd="0" click="0"/>
<GRAF id="7" typ="0" x="20" y="84" hcmd="0" click="0"/>
<CAM id="32" typ="0" x="383" y="531" url="some url" hcmd="0" click="0"/>
</ITEMS>
As you can see there are a few different element names in and they do not all have the same attributes.
I need to be able to retrieve the items by ID and preferable be able to retrieve the ID's of all TXT-items, or CAM-items, or y-items etc.
I'm using jQuery to parse the XML: $(xml).find('ITEMS').children('TXT').each(function() { }
and with code like $(this).attr("txt");
I'm building up the DOM - item by item - and it starts to get slow. I have a feeling there must be a better way. Store the XML in an array or object, process (sort) it and then build up the DOM at once.
Any thoughts?
Thanks!