Cross Browser XML Parsing

XML
load and process XML file

Tested and working in:

 

  • PC IE7
  • PC IE6
  • PC FireFox
  • PC Opera
  • Mac FireFox
  • Mac Safari 2

View XML

 

  • Javascript
    • /javascriptO2/importXml.js
      • importXML
      • MWJ_checkXMLLoad
    • /javascript/importXmlFunctions.js
  • XSLT
    • /xslt/crossBrowserXml.xslt 
    • This file is just the HREF that runs the JS function and has the div tag by which it writes out to.
      • <div id="writeroot"></div>

importXML
Pass the XML path and the function to run with the xml
importXML('xml/content/emperors.xml','createTable')

This function will then run the function that's passed with the XML as the only variable passed to it

createTable(xmlDoc)
This function is the custom function, but some features are common for XML parsing

  • var x = xmlDoc.getElementsByTagName('emperor');
  • for (j=0;j<x[0].childNodes.length;j++)
  • if (x[0].childNodes[j].nodeType != 1) continue;
  •     for (i=0;i<x.length;i++)
        {
            for (j=0;j<x[i].childNodes.length;j++)
            {
                if (x[i].childNodes[j].nodeType != 1) continue;
                var theData = document.createTextNode(x[i].childNodes[j].firstChild.nodeValue);
            }
        }