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 - Read XML from VBScript

Reply
 
Old 09-28-2008   #1 (permalink)
lekfir


 
 

Read XML from VBScript

Hi,

I have the following script that reads from an XML each row and performs an
action based on the attribute value in the line.

The problem is that my code doesn't continue to the next row after
performing the action (format) if needed or not needed...

I want it to check each row and continue to the next one till the end...

What should I change in my code?



Thanks!


The xml looks like that:


<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<Cases>
<Case MachineName="PC1" ImageFile="VISTA.WIN" ImageName="1"
FileSystem="NTFS" Test="FAM" NeedFormat="1" IsDone="0"/>
<Case MachineName="PC2" ImageFile="xp" ImageName="1" FileSystem="NTFS"
Test="FAM" NeedFormat="0" IsDone="0"/>
<Case MachineName="PC3" ImageFile="VISTA.WIN" ImageName="1"
FileSystem="NTFS" Test="stab" NeedFormat="1" IsDone="0"/>
<Case MachineName="PC4" ImageFile="VISTA.WIN" ImageName="1"
FileSystem="NTFS" Test="GoIO" NeedFormat="0" IsDone="0"/>

</Cases>

The VBS code:



XML_XPATH="Cases/Case"
XML_FILE="CASESLIST.XML"
SET MachineParm = WScript.Arguments



' ****************** Script start
************************************************** **************
IF WScript.Arguments.Count > 0 THEN
SET objXMLDoc = CreateObject("Microsoft.XMLDOM")
objXMLDoc.async = "FALSE"
objXMLDoc.load(XML_FILE)



SET Cases = objXMLDoc.getElementsByTagName(XML_XPATH)
IF Cases.length > 0 THEN
For each CurrentCase in Cases
IF MachineParm(0)=CurrentCase.Attributes.getNamedItem ("MachineName").text
And (CurrentCase.Attributes.getNamedItem("NeedFormat") .value) THEN

SET WshShell = CreateObject("WScript.Shell") 'Load WSshell object for system
operations
FSImage = CurrentCase.Attributes.getNamedItem("FileSystem"). text

Execute("FORMAT C: /FS:"& FSImage &" /Q" &" /Y")

CurrentCase.SETAttribute "IsDone","TRUE"

objXMLDoc.save(XML_FILE)

ELSE CurrentCase.SETAttribute "IsDone","TRUE"

objXMLDoc.save(XML_FILE)
End IF

Next
End IF

End IF


My System SpecsSystem Spec
Old 09-28-2008   #2 (permalink)
News


 
 

Re: Read XML from VBScript

Inserting the following after the For/Each statement reveals that it does
loop thru the Cases

WScript.Echo CurrentCase.Attributes.getNamedItem("MachineName").text



"lekfir" <lekfir@xxxxxx> wrote in message
news:06F55B21-5F84-4CCA-BC73-890BCABD4ECE@xxxxxx
Quote:

> Hi,
>
> I have the following script that reads from an XML each row and performs
> an
> action based on the attribute value in the line.
>
> The problem is that my code doesn't continue to the next row after
> performing the action (format) if needed or not needed...
>
> I want it to check each row and continue to the next one till the end...
>
> What should I change in my code?
>
>
>
> Thanks!
>
>
> The xml looks like that:
>
>
> <?xml version="1.0" encoding="UTF-8" standalone="yes"?>
> <Cases>
> <Case MachineName="PC1" ImageFile="VISTA.WIN" ImageName="1"
> FileSystem="NTFS" Test="FAM" NeedFormat="1" IsDone="0"/>
> <Case MachineName="PC2" ImageFile="xp" ImageName="1" FileSystem="NTFS"
> Test="FAM" NeedFormat="0" IsDone="0"/>
> <Case MachineName="PC3" ImageFile="VISTA.WIN" ImageName="1"
> FileSystem="NTFS" Test="stab" NeedFormat="1" IsDone="0"/>
> <Case MachineName="PC4" ImageFile="VISTA.WIN" ImageName="1"
> FileSystem="NTFS" Test="GoIO" NeedFormat="0" IsDone="0"/>
>
> </Cases>
>
> The VBS code:
>
>
>
> XML_XPATH="Cases/Case"
> XML_FILE="CASESLIST.XML"
> SET MachineParm = WScript.Arguments
>
>
>
> ' ****************** Script start
> ************************************************** **************
> IF WScript.Arguments.Count > 0 THEN
> SET objXMLDoc = CreateObject("Microsoft.XMLDOM")
> objXMLDoc.async = "FALSE"
> objXMLDoc.load(XML_FILE)
>
>
>
> SET Cases = objXMLDoc.getElementsByTagName(XML_XPATH)
> IF Cases.length > 0 THEN
> For each CurrentCase in Cases
> IF MachineParm(0)=CurrentCase.Attributes.getNamedItem ("MachineName").text
> And (CurrentCase.Attributes.getNamedItem("NeedFormat") .value) THEN
>
> SET WshShell = CreateObject("WScript.Shell") 'Load WSshell object for
> system
> operations
> FSImage = CurrentCase.Attributes.getNamedItem("FileSystem"). text
>
> Execute("FORMAT C: /FS:"& FSImage &" /Q" &" /Y")
>
> CurrentCase.SETAttribute "IsDone","TRUE"
>
> objXMLDoc.save(XML_FILE)
>
> ELSE CurrentCase.SETAttribute "IsDone","TRUE"
>
> objXMLDoc.save(XML_FILE)
> End IF
>
> Next
> End IF
>
> End IF
>

My System SpecsSystem Spec
Reply

Thread Tools


Similar Threads
Thread Forum
Can VBScript read foxpro 2.6 database? VB Script
Read messages turn UN-read again Live Mail
How to do No hang up VBScript (nohup for VBScript) VB Script
READ THIS IF YOU CANNOT GET DRIVE TO READ DISK TO FIX VISTA ERROR! Vista hardware & devices
Folders/files read only/can't create new folder in read only folde Vista account administration


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