Friday, January 22, 2010

Appending a string at the end of a text node in XML file.

Example 4: Appending a string at the end of a text node in XML file.



Creating XMLDOM object and Loading it. The async property specifies whether downloading of an XML file should be handled asynchronously or not. True means that the load() method returns the control to the caller before the download is complete. False means that the download must be completed before the caller gets the control back.
Set xmlDoc = CreateObject("Msxml2.DOMDocument")
xmlDoc.async=false
xmlDoc.load("C:\an.xml")
The getElementsByTagName method returns a NodeList collection of those elements with the tag name specified as the argument.
set x=xmlDoc.getElementsByTagName("Empid")(0).childNodes(0)
x.appendData(" - Sachin")
xmlDoc.save ("C:\an.xml")
msgbox(x.data)

After appending a text to a first Empid node:



Also See:
Explain XML and XML DOM
VBScript to access number of child nodes and text/nodename of each child node from XML file.
VBScript to access node name and node type of all nodes from XML document.
VBScript to add a new node in XML document.
VBScript to compare two XML files and show the differences in a messagebox.