PHWinfo banniere

Titres
PORTAIL ANNUAIRE ARTICLES COMPARATEUR HÉBERGEURS DEVIS FORUMS RÉDUCTEUR D'URL
Précédent   PHWinfo > Forums Hébergement > Forum Hébergement serveur > ms.win.server.scripting > Need a Script to pull specific data from an xml file
S'inscrire FAQ Membres Recherche Messages du jour Marquer les forums comme lus
Need a Script to pull specific data from an xml file

Réponse
 
LinkBack Outils de la discussion
Vieux 28/11/2007, 15h28   #1
Tfarmer
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Need a Script to pull specific data from an xml file

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 would be greatly appreciated.

Thank you.
  Réponse avec citation
Vieux 28/11/2007, 18h00   #2
Tom Lavedas
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: Need a Script to pull specific data from an xml file

On Nov 28, 9:28 am, Tfarmer <Tfar...@discussions.microsoft.com> 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 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/d...a-b8814fe2da5a

HTH

Tom Lavedas
===========
http://members.cox.net/tglbatch/wsh/
  Réponse avec citation
Vieux 28/11/2007, 18h16   #3
Tfarmer
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: Need a Script to pull specific data from an xml file

Thanks a million I'll see if I can get this script working.

"Tom Lavedas" wrote:

> On Nov 28, 9:28 am, Tfarmer <Tfar...@discussions.microsoft.com> 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 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/d...a-b8814fe2da5a
>
> HTH
>
> Tom Lavedas
> ===========
> http://members.cox.net/tglbatch/wsh/
>

  Réponse avec citation
Réponse


Outils de la discussion

Règles de messages
Vous ne pouvez pas créer de nouvelles discussions
Vous ne pouvez pas envoyer des réponses
Vous ne pouvez pas envoyer des pièces jointes
Vous ne pouvez pas modifier vos messages

Les balises BB sont activées : oui
Les smileys sont activés : oui
La balise [IMG] est activée : oui
Le code HTML peut être employé : non
Trackbacks are oui
Pingbacks are oui
Refbacks are oui


Fuseau horaire GMT +1. Il est actuellement 01h44.


Édité par : vBulletin® version 3.7.4
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.2.0 RC5 Tous droits réservés.
Version française #16 par l'association vBulletin francophone
PHWinfo est un site Éducation Sans Frontières ©2000-2008
Ad Management by RedTyger
©Tous droits réservés par les parties respectives
Page generated in 0,17158 seconds with 11 queries