I am trying to parse an XML document but i am a little bit confused just how i go about it. For example below shows my XML document
<document>
<object name="Customer" type="class" x="137" y="63">
<attributes>
</attributes>
<methods>
</methods>
</object>
<object name="Item" type="class" x="539" y="275">
<attributes>
</attributes>
<methods>
</methods>
</object>
<link start="Customer" end="Item" type="generalization" />
</document>
In my case i need to loop through each "object" and create an object, in my app, this is simple enough: objectArray.push(new uml_Class(name));
.
Now how would i loop through each <object>
on the document and then insert its name value into an array?
I've read that the function getElementsByTagName()
is to be used but this does not work for me:
alert(documentXML);
var root = documentXML.getElementsByTagName('Object');
It does alert my XML in the documentXML
variable but then firebug tells me the following:
documentXML.getElementsByTagName is not a function
How would i loop through an XML document, repeatedly making objects?
documentXML.all["object"]
? – Mark Linus May 9 '12 at 0:12