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?
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?
http://www.w3schools.com/dom/dom_access.asp?output=print
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.
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
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
You have to use recursive calls :
xmlDoc=new ActiveXObject("Microsoft.X MLDOM")
xmlDoc.async="false"
xmlDoc.load("note.xml")
readChildren(xmlDoc.docume ntElement. childNodes );
function readChildren(nodeList)
{
for (x in nodeList)
{
document.write(x.nodename)
document.write(": ")
document.write(x.text)
}
if(nodeList.hasChildNodes)
readChildren(nodeList.chil dNodes);
}
Eric
xmlDoc=new ActiveXObject("Microsoft.X
xmlDoc.async="false"
xmlDoc.load("note.xml")
readChildren(xmlDoc.docume
function readChildren(nodeList)
{
for (x in nodeList)
{
document.write(x.nodename)
document.write(": ")
document.write(x.text)
}
if(nodeList.hasChildNodes)
readChildren(nodeList.chil
}
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
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
http://builder.com.com/5100-6371_14-1044764-2.html