Object Attr CDATASection
CharacterData Comment Document DocumentFragment
DocumentType Entity EntityReference Node
Notation ProcessingInstruction Text
Object.removeChild(oldChild)
The removeChild method removes the specified node from the list of children and
returns it.
Using the 'names.xml' file the following example removes the third 'name'
element (Charlie) from the NodeList of the root element's
children and appends it to the end. The code then iterates through the
Node collection displaying the value of the first child (the
text node) of each.
XML:
<names>
<name>Alice</name>
<name>Bert</name>
<name>Charlie</name>
<name>Diane</name>
<name>Eric</name>
</names>
Code (VBScript):
Set objXMLDoc = CreateObject("Microsoft.XMLDOM")
objXMLDoc.async = False
objXMLDoc.load("names.xml")
Set objRoot = objXMLDoc.documentElement
Set objExNode = objRoot.removeChild(objRoot.childNodes.item(2))
objRoot.appendChild(objExNode)
Set objNodeList = objXMLDoc.getElementsByTagName("name")
For Each elem in objNodeList
document.write(elem.firstChild.nodeValue & "<br>")
Next
Output:
Alice
Bert
Diane
Eric
Charlie
|