Tuesday, September 30, 2008

Javascript consumes Xml File

<race>
<yatch raceNo='74'>
<name>wanderer</name>
<skipper>Walter Jeffries</skipper>
<helm>Sally Jacobs</helm>
</yatch>
</race>


Javascript load a xml file
into memory and create an object for accessing

var myXmlDoc = new ActiveXObject("Microsoft.XMLDOM");
myXmlDoc.async = false;
myXmlDoc.load("exampleDoc.xml");



// access elements
myXmlDoc.childNotes(0).childNodes(1).tagName;
myXmlDoc.childNotes(0).getAttribute("raceNo");
myXmlDoc.childNotes(0).childNotes(1).text;

No comments: