// This is a recursive function, which traverses the // entire document and prints out a list of all the // element node names into string variable myString. // We then erase the page and display this document. // Now find document root node, then traverse the // document tree (starting from the root node), and // find out information about the tree. ELEMENT_NODE = 1; // MS parser doesn't define Node.ELEMENT_NODE TEXT_NODE = 3; // MS parser doesn't define NODE.TEXT_NODE var xml = new ActiveXObject("microsoft.xmldom"); xml.async = false; xml.preserveWhiteSpace = 1; xml.load("./test-xml.xml"); if(xml.parseError.reason != "") { alert("XML Parser Error: " +xml.parseError.reason); exit; } root = xml.documentElement; // Start here contentString = traverseTree(root); // function returns a string function traverseTree(node) { if(node.nodeType == ELEMENT_NODE) { // Do this if the node is a markup element var name = node.nodeName; myString = '
  • Element: '+name; if( node.hasChildNodes() ) { myString = myString + '\n