...

View Full Version : XMLDOM question-returns all nodes without the first



umen1
10-04-2004, 12:16 PM
Hello
i have xml structure lts say something like this:

<root>
<foo1>
<foo2>
</foo2>
</foo1>
</root>

now i like to get this xml and return only the structure without the <root> node so the result will be something like:

<foo1>
<foo2>
</foo2>
</foo1>

i can only use javascript with this XMLDOM.
from what i was reading the direction is the selectNodes() method.
but i have trouble to implant it and get the desire results .

liorean
10-04-2004, 12:27 PM
Moving over to the DOM subforum of JavaScript programming.

One way of doing this is to simply reference the childNodes property of the root node.

umen1
10-04-2004, 02:05 PM
can you give me please simple example for me to start ?
tnx

jkd
10-04-2004, 07:37 PM
var root = document.getElementsByTagName("root")[0];
var range = document.createRange();
range.selectNodeContents(root);

`range` is now a range selecting the contents of the root node. From there you can use whichever range methods to manipulate it.

umen1
10-05-2004, 09:13 AM
Thank for the replay
the thing is im doing this script with WHS , and i have some problem to use "document.createRange();"
what i need to use instead of document.createRange(); when im working with WHS?
thanks

codegoboom
10-05-2004, 11:29 AM
Did someone say WSH?

Uh... the xml property could work:


<job>
<script language="JScript">
with(WScript)
{
var oXMLDOMDocument = CreateObject("Msxml2.DOMDocument.4.0");
oXMLDOMDocument.loadXML("<root><foo1><foo2><\/foo2><\/foo1><\/root>");
Echo(oXMLDOMDocument.documentElement.firstChild.xml);
}
</script>
</job>

umen1
10-05-2004, 12:03 PM
well when i try to load external xml file , i only get the first node with your script .
instead of oXMLDOMDocument.loadXML("<root><foo1><foo2><\/foo2><\/foo1><\/root>");
im using oXMLDOMDocument.load("source.xml");
and i get only the first node.

can i use createRange(); with WSH?

codegoboom
10-05-2004, 12:55 PM
Well, if it's all childNodes you want, just grab the xml of each...


<job>
<script language="JScript">
with(WScript)
{
var oXMLDOMDocument = CreateObject("Msxml2.DOMDocument.4.0");
oXMLDOMDocument.load("source.xml");
var enumRC = new Enumerator(oXMLDOMDocument.documentElement.childNodes);
var xmlStr = "";
while(!enumRC.atEnd())
{
xmlStr += "\n" + enumRC.item().xml;
enumRC.moveNext();
}
Echo(xmlStr.substr(1));
}
</script>
</job>



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum