![]() |
![]() | ![]() | ![]() | ![]() | ![]() | ![]() | ![]() |
| 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) |
| | 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 Specs![]() |
| | #2 (permalink) |
| | 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 Specs![]() |
![]() |
| 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 | |||