dimanche 19 avril 2015

VBA Start at first node if it exists - using If Is Nothing

How can I increment through each parent node starting from the first to the last and apply:



For Each n In XMLFile.SelectNodes("/catalog/book")
If XMLFile.SelectSingleNode("/catalog/book/banana") Is Nothing Then
MsgBox ("banana not here")
Else
MsgBox ("banana found")
End If
Next


banana does not exist in the first book:



?xml version="1.0"?>
<catalog>
<book id="Adventure">
<author>Ralls, Kim</author>
<title>XML Developer's Guide</title>
<price>44.95</price>
</book>
<book id="Adventure">
<author>Ralls, Kim</author>
<title>Midnight Rain</title>
<price>5.95</price>
<banana>ring</banana>
</book>
<book id="Adventure">
<author>Ralls, Kim</author>
<title>Mist</title>
<price>15.95</price>
<banana>ring</banana>
</book>
<book id="Mystery">
<author>Ralls, Kim</author>
<title>Some Mystery Book</title>
<price>9.95</price>
<banana>ring</banana>
</book>
</catalog>


Current Output: "banana found" "banana found" "banana found" "banana found"


Aucun commentaire:

Enregistrer un commentaire