harry0812 Posted September 20, 2011 Share Posted September 20, 2011 Can someome please give me a dummy script that reads a data from a multilvel XML and parses it using Javascript and displays it in the html page. The catch is :- You are not allowed to use getElementByName and getElementById, etc... Only nodeType, childnode and other such attribuit is allowed.Please assist me here. Link to comment Share on other sites More sharing options...
boen_robot Posted September 20, 2011 Share Posted September 20, 2011 Well yeah, getElementByName and getElementById don't make sense in an XML context (well, IDs do in special circumstances, but that's another story). See the examples in DOM Access Nodes Link to comment Share on other sites More sharing options...
harry0812 Posted September 21, 2011 Author Share Posted September 21, 2011 I did try that. But its not able to parse a multilevel XML.eg :<a><b></b> <c> <d></d> <e></e> </c></a> Link to comment Share on other sites More sharing options...
harry0812 Posted September 21, 2011 Author Share Posted September 21, 2011 I did find a way out . Can someone help me convert the below small script from vbscript to javascript. set xmlDoc=CreateObject("Microsoft.XMLDOM")xmlDoc.async="false"xmlDoc.load("nba.xml")for each x in xmlDoc.documentElement.childNodes; document.write("<b>" + x.nodename + "</b>"); document.write(": "); document.write(x.text); document.write("<br>");next Link to comment Share on other sites More sharing options...
soccerkingpilot Posted June 22, 2012 Share Posted June 22, 2012 Did you ever figure this out? I'm running into a similar issue. Thanks. Link to comment Share on other sites More sharing options...
japisoft Posted June 29, 2012 Share Posted June 29, 2012 var document = ... // XML document var root = document.documentElement;var children = root.childNodes();for ( var i = 0; i < children.length; i++ ) { var node = children[ i ]; if ( node.nodeName == "myName" ) { .... }} You can repeat at any level this kind of loop, you may also use nodeType for filtering elements. Best regards Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now