![]() |
![]() | ![]() | ![]() | ![]() | ![]() | ![]() | ![]() |
| 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. |
| |||||||
![]() |
| |
| | #1 (permalink) |
| | 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 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 me to come up with something more constructive. |
My System Specs![]() |
| | #2 (permalink) |
| | 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: > 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 Specs![]() |
![]() |
| 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 | |||