i have app read xmls files without knowing schema. in php , use following simple code read , loop through each element:
$reader = new xmlreader(); $reader->open($fname); while ($reader->read()) { $depth = $reader->depth; }
this takes me through every element of file 1 one. depth , graphical representation of xml file indented given have depth element of each node.
i'd in js can't seem figure out how. code below loops through xml elements can't retrieve depth element. can node name, type , value not depth... thanks!
<!doctype html> <html> <body> <p id="demo"></p> <script> var xhttp = new xmlhttprequest(); xhttp.onreadystatechange = function() { if (this.readystate == 4 && this.status == 200) { myfunction(this); } }; xhttp.open("get", "books.xml", true); xhttp.send(); function myfunction(xml) { var x, i, xmldoc, txt; xmldoc = xml.responsexml; txt = ""; x = xmldoc.documentelement.childnodes; (i = 0; < x.length; i++) { if (x[i].nodetype == 1) { txt += x[i].nodename + "<br>"; } } document.getelementbyid("demo").innerhtml = txt; } </script>
Comments
Post a Comment