Update XML with VBScript

This script allows to update data in a XML file.

  • In this example, the following XML file is edited: “C:\Program Files (x86)\Editor\Application\MyFile.xml”
  • The modification will affect the following node in the XML: “//parentnode/targetnode”
  • The new value inside the node is: “Value to add in the node”

To play with XML files, the object “Microsoft.XMLDOM” must be used.

MSDN: https://msdn.microsoft.com/en-us/library/ms757828(v=vs.85).aspx

Const XMLFILE = "C:\Program Files (x86)\Editor\Application\MyFile.xml"
Const XMLNODE = "//parentnode/targetnode"
Const XMLVALUE = "Value to add in the node"

Set xmlDoc = CreateObject("Microsoft.XMLDOM")
xmlDoc.load XMLFILE

'Locate the desired node
Set nNode = xmlDoc.selectsinglenode (XMLNODE)

'Set the node text with the new value
nNode.text = XMLVALUE

'Save the xml document with the new settings.
strResult = xmldoc.save(XMLFILE)