XML to JavaScript : XML : Development : JavaScript DHTML examples (example source code) Organized by topic

JavaScript DHTML
C++
PHP
JavaScript DHTML Home »  Development   » [  XML  ]   
 



XML to JavaScript

 // convert XML data into JavaScript array of JavaScript objects
function XML2JS(xmlDoc, containerTag) {
    var output = new Array();
    var rawData = xmlDoc.getElementsByTagName(containerTag)[0];
    var i, j, oneRecord, oneObject;
    for (i = 0; i < rawData.childNodes.length; i++) {
        if (rawData.childNodes[i].nodeType == 1) {
            oneRecord = rawData.childNodes[i];
            oneObject = output[output.lengthnew Object();
            for (j = 0; j < oneRecord.childNodes.length; j++) {
                if (oneRecord.childNodes[j].nodeType == 1) {
                    oneObject[oneRecord.childNodes[j].tagName
                        oneRecord.childNodes[j].firstChild.nodeValue;    
                }
            }
        }
    }
    return output;
}


           
       
Related examples in the same category
1.  Loads a XML file and permits to access to the data it contains
2.  function loads the XML document from the specified URL
3.  Convert XML to HTML
4.  Display XML content in HTML table








Home| Contact Us
Copyright 2003 - 04 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.