VBScriptバージョン(便利なドキュメントで使用するのが最適):
' 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
ForEachLoopを使用できます。
Dim ndRow
For Each ndRow In ndlRow
WScript.Echo "send mail to", ndRow.getAttribute("hello")
Next