Jump to content

Simple Javascript Xml Parsing


harry0812
 Share

Recommended Posts

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

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

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

  • 9 months later...
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

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...