Jump to content
harry0812

Simple Javascript Xml Parsing

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.

Share this post


Link to post
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

Share this post


Link to post
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

Share this post


Link to post
Share on other sites
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

Share this post


Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...

×
×
  • Create New...