Go Back   CodingForums.com > :: Client side development > JavaScript programming > DOM and JSON scripting

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 10-04-2004, 12:16 PM   PM User | #1
umen1
New to the CF scene

 
Join Date: Sep 2004
Posts: 8
Thanks: 0
Thanked 0 Times in 0 Posts
umen1 is an unknown quantity at this point
XMLDOM question-returns all nodes without the first

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 .
umen1 is offline   Reply With Quote
Old 10-04-2004, 12:27 PM   PM User | #2
liorean
The thread killer


 
Join Date: Feb 2003
Location: Umeå, Sweden
Posts: 5,575
Thanks: 0
Thanked 84 Times in 75 Posts
liorean will become famous soon enoughliorean will become famous soon enough
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.
__________________
liorean <[lio@wg]>
Articles: RegEx evolt wsabstract , Named Arguments
Useful Threads: JavaScript Docs & Refs, FAQ - HTML & CSS Docs, FAQ - XML Doc & Refs
Moz: JavaScript DOM Interfaces MSDN: JScript DHTML KDE: KJS KHTML Opera: Standards
liorean is offline   Reply With Quote
Old 10-04-2004, 02:05 PM   PM User | #3
umen1
New to the CF scene

 
Join Date: Sep 2004
Posts: 8
Thanks: 0
Thanked 0 Times in 0 Posts
umen1 is an unknown quantity at this point
can you give me please simple example for me to start ?
tnx
umen1 is offline   Reply With Quote
Old 10-04-2004, 07:37 PM   PM User | #4
jkd
Senior Coder

 
jkd's Avatar
 
Join Date: May 2002
Location: metro DC
Posts: 3,163
Thanks: 1
Thanked 18 Times in 18 Posts
jkd will become famous soon enough
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.
__________________
jasonkarldavis.com
jkd is offline   Reply With Quote
Old 10-05-2004, 09:13 AM   PM User | #5
umen1
New to the CF scene

 
Join Date: Sep 2004
Posts: 8
Thanks: 0
Thanked 0 Times in 0 Posts
umen1 is an unknown quantity at this point
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
umen1 is offline   Reply With Quote
Old 10-05-2004, 11:29 AM   PM User | #6
codegoboom
Regular Coder

 
Join Date: Aug 2004
Location: codegoboom@yahoo.com
Posts: 999
Thanks: 0
Thanked 0 Times in 0 Posts
codegoboom is an unknown quantity at this point
Did someone say WSH?
Uh... the xml property could work:
Code:
<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>
__________________
*this message will self destruct in n-seconds*
codegoboom is offline   Reply With Quote
Old 10-05-2004, 12:03 PM   PM User | #7
umen1
New to the CF scene

 
Join Date: Sep 2004
Posts: 8
Thanks: 0
Thanked 0 Times in 0 Posts
umen1 is an unknown quantity at this point
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?
umen1 is offline   Reply With Quote
Old 10-05-2004, 12:55 PM   PM User | #8
codegoboom
Regular Coder

 
Join Date: Aug 2004
Location: codegoboom@yahoo.com
Posts: 999
Thanks: 0
Thanked 0 Times in 0 Posts
codegoboom is an unknown quantity at this point
Well, if it's all childNodes you want, just grab the xml of each...

Code:
<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>
__________________
*this message will self destruct in n-seconds*

Last edited by codegoboom; 10-05-2004 at 01:17 PM.. Reason: one too many...
codegoboom is offline   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 08:47 AM.


Advertisement
Log in to turn off these ads.