METHOD:  Object::appendChild

Object  Attr   CDATASection   CharacterData   Comment   Document   DocumentFragment   DocumentType   Entity   EntityReference   Node   Notation   ProcessingInstruction   Text
 
Object.appendChild(tagName)

The appendChild method appends a new child node to the end of the list of children for this node. If the child node is already in the tree, it is first removed.

To demonstrate this method, the following example uses the 'names.xml' file and creates a new 'name' element and a text node with the value of 'John' which is appended to it. The new 'name' element is then appended to the document's root element, and finally the variable objCurrNode is set to the root's last child (the newly-appended 'name' element), and the value of its first child (the text node) is displayed.

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")

Dim objCurrNode, objNewNode, objNewText
Set objNewNode = objXMLDoc.createElement("name")
Set objNewText = objXMLDoc.createTextNode("John")
objNewNode.appendChild(objNewText)

Set objCurrNode = objXMLDoc.documentElement
objCurrNode.appendChild(objNewNode)
Set objCurrNode = objCurrNode.lastChild
document.write(objCurrNode.firstChild.nodeValue)

Output:
John



Copyright 1999-2001 by Infinite Software Solutions, Inc. All rights reserved.
Trademark Information