VBScript的版本(最好與Docs方便使用):
' Assuming you have a string in gXML, I fake it here, please
' note the closing of the row nodes!
Dim gXML : gXML = Join(Array(_
"<root>" _
, " <Lease>" _
, " <row hello=""[email protected]""/>" _
, " <row hello=""[email protected]""/>" _
, " <row hello=""[email protected]""/>" _
, " <row hello=""[email protected]""/>" _
, " </Lease>" _
, "</root>" _
), "")
Dim oXML : Set oXML = CreateObject("Msxml2.DOMDocument")
oXML.loadXml gXML
If 0 = oXML.ParseError Then
Dim ndlRow : Set ndlRow = oXML.selectNodes("/root/Lease/row")
If 0 < ndlRow.length Then
Dim nRow
For nRow = 0 To (ndlRow.length - 1)
WScript.Echo nRow, "send mail to", ndlRow(nRow).getAttribute("hello")
Next
Else
WScript.Echo "no rows found"
End If
Else
WScript.Echo oXML.parseError.reason
End If
輸出:
0 send mail to [email protected]
1 send mail to [email protected]
2 send mail to [email protected]
3 send mail to [email protected]
取而代之的是計算環路的
For nRow = 0 To (ndlRow.length - 1)
WScript.Echo nRow, "send mail to", ndlRow(nRow).getAttribute("hello")
Next
你可以使用一個For Each Loop:
Dim ndRow
For Each ndRow In ndlRow
WScript.Echo "send mail to", ndRow.getAttribute("hello")
Next