Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 8 of 8
  1. #1
    New to the CF scene
    Join Date
    Sep 2004
    Posts
    8
    Thanks
    0
    Thanked 0 Times in 0 Posts

    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 .

  • #2
    Master Coder
    Join Date
    Feb 2003
    Location
    UmeŚ, Sweden
    Posts
    5,575
    Thanks
    0
    Thanked 83 Times in 74 Posts
    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

  • #3
    New to the CF scene
    Join Date
    Sep 2004
    Posts
    8
    Thanks
    0
    Thanked 0 Times in 0 Posts
    can you give me please simple example for me to start ?
    tnx

  • #4
    jkd
    jkd is offline
    Senior Coder jkd's Avatar
    Join Date
    May 2002
    Location
    metro DC
    Posts
    3,163
    Thanks
    1
    Thanked 18 Times in 18 Posts
    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.

  • #5
    New to the CF scene
    Join Date
    Sep 2004
    Posts
    8
    Thanks
    0
    Thanked 0 Times in 0 Posts
    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

  • #6
    Regular Coder
    Join Date
    Aug 2004
    Location
    codegoboom@yahoo.com
    Posts
    999
    Thanks
    0
    Thanked 0 Times in 0 Posts
    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*

  • #7
    New to the CF scene
    Join Date
    Sep 2004
    Posts
    8
    Thanks
    0
    Thanked 0 Times in 0 Posts
    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?

  • #8
    Regular Coder
    Join Date
    Aug 2004
    Location
    codegoboom@yahoo.com
    Posts
    999
    Thanks
    0
    Thanked 0 Times in 0 Posts
    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>
    Last edited by codegoboom; 10-05-2004 at 01:17 PM. Reason: one too many...
    *this message will self destruct in n-seconds*


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •