Torgeir
Tue Jan 25 12:53:28 CST 2005
Jeffrey wrote:
> I have created a template xml file, but unsure exactly how to read the
> values using vbscript. I want to read the Application Name and Version
> number and store in a varible to do a comparision. I was looking at xml
> language. I was thinking I needed to select the nodes Application name and
> enumerate thorugh all Application names. Then get the attributes for each
> Application Name.
>
> I just need some direction.
>
> <Versioning>
> <Application Name="IBDI Version" Version="2.7" ENVName="IBDIADSVERSION"/>
> <Application Name="State City" Version="3.9.0" ENVName="STATECITYVERSION"/>
> <Application Name="ICS" Version="9.11.0" ENVName="RCSVERSION"/>
> <Application Name="Release" Version="3.5.009" ENVName="RELEASEVERSION"/>
> <Application Name="Web" Version="5.13.0" ENVName="WEBVERSION"/>
> </Versioning>
Hi
Here is a script that puts the application names and versions
into a dictionary object:
'--------------------8<----------------------
sFilePath = "C:\something\data.xml"
sXPath = "/Versioning/Application"
Set oXMLDoc = CreateObject("MSXML2.DOMDocument")
oXMLDoc.SetProperty "SelectionLanguage", "XPath"
oXMLDoc.Async = False
oXMLDoc.Load sFilePath
If (oXMLDoc.parseError.errorCode <> 0) Then
Set oErr = oXMLDoc.ParseError
WScript.Echo "Could not load file " & sFilePath _
& " , error: " & oErr.Reason
WScript.Quit
End If
Set dApps = CreateObject("Scripting.Dictionary")
dApps.CompareMode = vbTextCompare
Set oApps = oXMLDoc.DocumentElement.SelectNodes(sXPath)
For Each oApp in oApps
dApps.Add oApp.getAttribute("Name"), oApp.getAttribute("Version")
Next
' enumerate the dictionary object, echoing both the key and item value:
For Each sApp In dApps
WScript.Echo "Applcation: " & sApp & " Version: " & dApps.Item(sApp)
Next
' Checking if a spesific key exists, and display the item value
If dApps.Exists("State City") Then
WScript.Echo "The application State City exists in the list, version is " _
& dApps.Item("State City")
End If
'--------------------8<----------------------
--
torgeir, Microsoft MVP Scripting and WMI, Porsgrunn Norway
Administration scripting examples and an ONLINE version of
the 1328 page Scripting Guide:
http://www.microsoft.com/technet/scriptcenter/default.mspx