Re: Need a Script to pull specific data from an xml file

Tech-Archive recommends: Repair Windows Errors & Optimize Windows Performance



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/
.



Relevant Pages

  • Re: Need a Script to pull specific data from an xml file
    ... "Tom Lavedas" wrote: ... I'm a script newbie so any and all help would be greatly appreciated. ... If dApps.Exists("State City") Then ... The other part of your problem is searching a folder for XML files, ...
    (microsoft.public.windows.server.scripting)
  • Re: Need helpf with javascript if else
    ... > the city selection they choose. ... > String path = request.getContextPath; ... It's quite okay to have script contained in just a bare body. ... {cityName: "city1name", ...
    (comp.lang.javascript)
  • Re: Looking for a PHP script to sort data/create pages according to fields.
    ... > This script will also accept data from people. ... (uses 2 letter abbr for state and country ... `city` varcharNOT NULL default '', ...
    (comp.lang.php)
  • Re: call vbScript from vba or convert vbscript to vba(Access 2007)?
    ... I have .vbs script that I use to loop through a series of xml files and ... I change it each time I run the script. ... Is there a good way of converting the .vbs into VBA? ... The VBA compiler will point out any remaining lines that fail to meet ...
    (microsoft.public.scripting.vbscript)
  • Help making this script better
    ... I am using Python 2.4, ... can use this script. ... # This sciript will process a directory of XML files and push them to ... def getFiles2Post: ...
    (comp.lang.python)