Windows Vista Forums
Vista Forums Home Join Vista Forums Windows 7 Forum Vista Tutorials Tags
Welcome to Windows Vista Forums. Our forum is dedicated to helping you find solutions with any problems, errors or issues you are experiencing with Windows Vista. The Vista forum also covers news and updates and has an extensive Windows Vista tutorial section that covers a wide range of tips and tricks.

Go Back   Vista Forums > Misc Newsgroups > VB Script

Vista - Re: xml script

Reply
 
Old 05-22-2009   #1 (permalink)
ekkehard.horner


 
 

Re: xml script

info schrieb:
Quote:

> Can anybody help me with this script.
>
> I have a script that read xml data , but i get a error in the For each
> loop.
> Microsoft VBScript runtime error: Object doesn't support this property or
> method
> I want to read all the lines ther are more data, it works fine with one
> line, if i marked the for each line and the Next line.
>
>
> Dim sFSpec : sFSpec = ".\UniversalManifest.xml"
> Dim sXPath : sXPath = "//Package"
> Dim sAttr : sAttr = "version"
> Dim sAttr1 : sAttr1 = "postdate"
>
> ' need a FSO for pathes and IO
> Dim oFS : Set oFS = CreateObject( "Scripting.FileSystemObject" )
> sFSpec = oFS.GetAbsolutePathName( sFSpec )
>
>
> ' Create an XML Document Object and specify XPath (to be on the safe side)
> Dim oXDoc : Set oXDoc = CreateObject( "Msxml2.DOMDocument.3.0" )
> oXDoc.setProperty "SelectionLanguage", "XPath"
> ' Load XML file
> oXDoc.async = False
> oXDoc.Load sFSpec
>
> ' Return the node for sXPath
> Dim oNode : Set oNode = oXDoc.selectSingleNode( sXPath )
>
>
> For Each objnode In oNode
you shouldn't suppose that oNode is a collection you can loop
over, before you test that oXDoc.selectSingleNode( sXPath )
returned something useable.
Quote:

> If oNode Is Nothing Then
Quote:

> WScript.Echo "not found"
> Else
> WScript.Echo oNode.getAttribute( sAttr ) & " -" &
> oNode.getAttribute( sAttr1 )
> End If
>
> Next
Posting (an illustrative fragment of) your .xml file may allow
me to come up with something more constructive.

My System SpecsSystem Spec
Old 05-22-2009   #2 (permalink)
ekkehard.horner


 
 

Re: xml script

info schrieb:
Quote:

> Here is the Forefront from Microsoft xml, i want to check the product -
> version and postdate.
[...]
Thanks for the sample!
Quote:

>
Try this (before or after you studied some documentation
about XPath expressions):

' Specs
Dim sFSpec : sFSpec = ".\tidy_universalmanifest.xml"
' get all Packages at the specified position/level in hierarchy
Dim sXPath : sXPath = "/UniversalManifest/EngineVersions/Platform/Category/Engine/Package"
' Dim sXPath : sXPath = "//Package" ' get all Packages regardless of position/level in
hierarchy
Dim aAttrs : aAttrs = Array( "version", "postdate" )

' need a FSO for pathes and IO
Dim oFS : Set oFS = CreateObject( "Scripting.FileSystemObject" )
sFSpec = oFS.GetAbsolutePathName( sFSpec )

' Create an XML Document Object and specify XPath (to be on the safe side)
Dim oXDoc : Set oXDoc = CreateObject( "Msxml2.DOMDocument" ) ' "Msxml2.DOMDocument.4.0"
oXDoc.setProperty "SelectionLanguage", "XPath"
' Load XML file
oXDoc.async = False
oXDoc.load sFSpec

If 0 = oXDoc.ParseError Then
WScript.Echo sFSpec, "looks ok"
Dim ndlFound : Set ndlFound = oXDoc.selectNodes( sXPath )
If 0 < ndlFound.length Then
WScript.Echo "|", sXPath, "| found"
WScript.Echo
Dim ndCur
For Each ndCur In ndlFound
' WScript.Echo "xml of node", ndCur.xml
WScript.Echo ndCur.parentNode.tagName, ndCur.parentNode.getAttribute( "name" )
Dim sAttr
For Each sAttr In aAttrs
WScript.Echo sAttr, ndCur.getAttribute( sAttr )
Next
WScript.Echo
Next
Else
WScript.Echo "|", sXPath, "| not found"
End If
Else
WScript.Echo oXDoc.ParseError.Reason
End If


output (for a 'closed version of your sample):

=== UnivManiXml: read universalmanifest.xml ===================================
C:\wis\_vbs\0506\dev\forum\tidy_universalmanifest.xml looks ok
| /UniversalManifest/EngineVersions/Platform/Category/Engine/Package | found

Engine CAVet
version 0905190001
postdate 2009-05-19T06:08:17.3324901-07:00

Engine AhnLab
version 0905190001
postdate 2009-05-19T00:02:50.6769656-07:00

Engine Sophos
version 0905190002
postdate 2009-05-19T03:43:12.8922911-07:00

Engine Microsoft
version 0905190001
postdate 2009-05-19T06:33:01.6756146-07:00

=== UnivManiXml: 0 done (00:00:00) ============================================

My System SpecsSystem Spec
Reply

Thread Tools


Similar Threads
Thread Forum
Logon Script Causing Laptops To Hang - Problems in script? VB Script
problem passing args to script 'There is no script engine for file extenstion' VB Script
Include another script, keep variables in included script? PowerShell
Script file has 'OS Handle' error when run from script PowerShell
Can you drag-n-drop a file on top of a PS script to run the script? PowerShell


Vista Forums is an independent web site and has not been authorized,
sponsored, or otherwise approved by Microsoft Corporation.
"Windows Vista", the Start Orb, and related materials are trademarks of Microsoft Corp.
© Designer Media Ltd

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46