I am trying to write a script that will manipulate some data for me in an xml file. I am pretty new to VBScript but have a VB.NET and VBA background, so I feel like I kind
Here is a small example:
Suppose you have a file called C:\Temp\Test.xml
with this contents:
<?xml version="1.0"?>
<root>
<property name="alpha" value="1"/>
<property name="beta" value="2"/>
<property name="gamma" value="3"/>
</root>
Then you can use this VBScript:
Set objDoc = CreateObject("MSXML.DOMDocument")
objDoc.Load "C:\Temp\Test.xml"
' Iterate over all elements contained in the <root> element:
Set objRoot = objDoc.documentElement
s = ""
t = ""
For Each child in objRoot.childNodes
s = s & child.getAttribute("name") & " "
t = t & child.getAttribute("value") & " "
Next
MsgBox s ' Displays "alpha beta gamma "
MsgBox t ' Displays "1 2 3 "
' Find a particular element using XPath:
Set objNode = objDoc.selectSingleNode("/root/property[@name='beta']")
MsgBox objNode.getAttribute("value") ' Displays 2
I hope this helps getting you started with VBScript and XML.