Link to home
Start Free TrialLog in
Avatar of fcp
fcp

asked on

XML Parsing

I'm trying to parse an XML file.
I've not problems in reading a node at time, but i'm stucked while reading the entire XML file.
I've a function that reads out tag, values, comments and all other things from a given node. If this node have child nodes, the the function calls itself... and after some calls all stops to works.
I've only found samples that reads nodes only "one at time" (think at a tree, only when you expand a branch)
How can i read all nodes and store them in a some manner?
Avatar of Michel Plungjan
Michel Plungjan
Flag of Denmark image

Avatar of fcp
fcp

ASKER

mmmhh
if you're pointing me to the first script (Traversing the node tree) i have some things to say about it
1) It's a VBScript (not Javascript)
2) It read all child nodes of the xmlDoc.documentElement, not the childnodes of the childnodes (and then the childnodes of the childnodes of the childnodes...)

This is (apart of the script language) exaxtly the point where i'm stucked.
ASKER CERTIFIED SOLUTION
Avatar of Michel Plungjan
Michel Plungjan
Flag of Denmark image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
You have to use recursive calls :


xmlDoc=new ActiveXObject("Microsoft.XMLDOM")
xmlDoc.async="false"
xmlDoc.load("note.xml")
readChildren(xmlDoc.documentElement.childNodes);

function readChildren(nodeList)
{
   for (x in nodeList)
   {
     document.write(x.nodename)
     document.write(": ")
     document.write(x.text)
   }
   if(nodeList.hasChildNodes)
      readChildren(nodeList.childNodes);
}

Eric

If you have a Schema file, you can use the XMLSchemaCache40 to do your parsing for you.
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/xmlsdk/htm/xsd_devgd_hdi_validate_9gma.asp

M
If I was on the right lines with my last post, here's an interesting article on Parsing with the DOM.
http://builder.com.com/5100-6371_14-1044764-2.html