I recently used the Displaying XML Data tutorial, but cant seem to figure out how to add more dynamic text fields and populate them with more <person> and <comment> attributes.
Here is my code:
function loadXML(loaded) {
if (loaded) {
_root.inventor = this.firstChild.childNodes[2].childNodes[0].firstChild.nodeValue;
_root.comments = this.firstChild.childNodes[2].childNodes[1].firstChild.nodeValue;
name_txt.text = _root.inventor;
comment_txt.text = _root.comments;
} else {
content = “file not loaded!”;
}
}
xmlData = new XML();
xmlData.ignoreWhite = true;
xmlData.onLoad = loadXML;
xmlData.load(“inventors.xml”);
and xml:
<?xml version=“1.0”?>
<inventors>
<person>
<name>Thomas Edison</name>
<comment>Inventor of many things such as the incandescent lightbulb.</comment>
</person>
<person>
<name>Doug Engelbart</name>
<comment>Invented the mouse at the Stanford Research Institute</comment>
</person>
<name>Patrick</name>
<comment>did this xml file</comment>
</person>
</inventors>
I am trying to display Patrick - and did this xml file.
Could you please help me figure out what I am doing wrong here?