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=""none@nowhere.com""/>" _
, " <row hello=""none@nowhere.com""/>" _
, " <row hello=""none@nowhere.com""/>" _
, " <row hello=""none@nowhere.com""/>" _
, " </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 none@nowhere.com
1 send mail to none@nowhere.com
2 send mail to none@nowhere.com
3 send mail to none@nowhere.com
而不是计数循环
For nRow = 0 To (ndlRow.length - 1)
WScript.Echo nRow, "send mail to", ndlRow(nRow).getAttribute("hello")
Next
您可以使用 For Each 循环:
Dim ndRow
For Each ndRow In ndlRow
WScript.Echo "send mail to", ndRow.getAttribute("hello")
Next