Re: Need a Script to pull specific data from an xml file
- From: Tom Lavedas <tglbatch@xxxxxxx>
- Date: Wed, 28 Nov 2007 09:00:19 -0800 (PST)
On Nov 28, 9:28 am, Tfarmer <Tfar...@xxxxxxxxxxxxxxxxxxxxxxxxx> wrote:
Ok what we are trying to do is make a script to search for and pull a job
number out of like 1000 xml files and put it into one file.
I'm a script newbie so any and all help would be greatly appreciated.
Thank you.
Here is an example script that I picked up a long time ago ...
sFilePath = "testcase.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
It parses an XML file structured like this ...
<?xml version="1.0" ?>
<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>
The other part of your problem is searching a folder for XML files,
which is done something like this (based on MS Script Center
example) ...
strComputer = "."
sSomefolder = createobject("wscript.shell").currentdirectory ' for
example
sPathspec = Replace(Mid(sSomefolder,3), "\", "\\") & "\\"
Set objWMIService = GetObject("winmgmts:" _
& "{impersonationLevel=impersonate}!\\" & strComputer & "\root
\cimv2")
Set colFiles = objWMIService.ExecQuery _
("Select * from CIM_Datafile Where Drive = 'C:' " _
& "AND Path = '" & sPathSpec & "' AND Extension = 'xml'")
with createobject("scripting.filesystemobject")_
.opentextfile("jobs.txt",2,true)
For Each objFile in colFiles
.writeline FindJobinXML(objFile.Name)
Next
end with
wsh.echo "Job search completed"
function FindJobinXML(Name)
'... you fill in the rest
FindJobinXML = xmlresult
end function
TechNet Script Center Sample Scripts (URL all one line)
http://www.microsoft.com/downloads/details.aspx?FamilyID=b4cb2678-dafb-4e30-b2da-b8814fe2da5a
HTH
Tom Lavedas
===========
http://members.cox.net/tglbatch/wsh/
.
- Follow-Ups:
- Re: Need a Script to pull specific data from an xml file
- From: Tfarmer
- Re: Need a Script to pull specific data from an xml file
- Prev by Date: Re: Limit user logon time in a domain Windows Server 2003 script
- Next by Date: Re: Need a Script to pull specific data from an xml file
- Previous by thread: Re: Limit user logon time in a domain Windows Server 2003 script
- Next by thread: Re: Need a Script to pull specific data from an xml file
- Index(es):
Relevant Pages
|