Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Query an xml doc using xpath

Status
Not open for further replies.

Guest_imported

New member
Jan 1, 1970
0
I need some help on this topic.

This is what I have tried so far
Won't work with the [@firstName = ""John""] part
the rest does.....

'*********************Code.vbs***************************
Dim DataSource,GetData,Row
Set DataSource = CreateObject("Microsoft.XMLDOM")
DataSource.async = False
DataSource.setProperty "SelectionLanguage", "XPath"
DataSource.load("DataSource.xml")
Set GetData = DataSource.documentElement.selectNodes("*/*[@firstName = ""John""]")
For Each Row In GetData
WScript.Echo Row.text
Next
'*************** DataSource.xml *********************
<?xml version=&quot;1.0&quot; encoding=&quot;ISO-8859-1&quot;?>
<addressBook>
<address>
<firstName>John</firstName>
<surname>Smith</surname>
<email>smithj@world.org</email>
<tel type = &quot;work&quot;>234-123-222</tel>
</address>
</addressBook>
 
Try this

Dim DataSource,GetData,Row
Set DataSource = CreateObject(&quot;Microsoft.XMLDOM&quot;)
DataSource.async = False

DataSource.load(&quot;DataSource.xml&quot;)
Set GetData = DataSource.documentElement.selectNodes(&quot;//firstName&quot;)
For Each Row In GetData
msgbox Row.text
Next

THe @ is used for an attribute, not an element
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top