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 biv343 on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Beginner Xpath Query

Status
Not open for further replies.

simonchristieis

Programmer
Jan 10, 2002
1,144
GB
I have an xml file

<aaa>
<bbb>
<name>Billy</name>
<age>34</age>
<telephone>123</telephone>
</bbb>
</aaa>


and am running an xpath query against it, but i cant return specific details


set xmlDoc=CreateObject(&quot;Microsoft.XMLDOM&quot;)
xmlDoc.async=&quot;false&quot;
xmlDoc.load(&quot;xml/contact.xml&quot;)

i=&quot;Billy&quot;


' Xpath Query
set nodes=xmlDoc.selectNodes(&quot;aaa/bbb[name='&quot; & i & &quot;']/*&quot;)


****** this is where the problem lies
****** I want to return the value of telephone

html = nodes.item('telephone').text


alert(html)

id be grateful for any help

thanks in advance
 
this worked for me (as a vbscript file):

dim xmlDoc, nodes, i, html

set xmlDoc=CreateObject(&quot;Microsoft.XMLDOM&quot;)
xmlDoc.async=false
xmlDoc.load(&quot;contact.xml&quot;)

i=&quot;Billy&quot;

html = xmlDoc.selectSingleNode(&quot;aaa/bbb[name='&quot; & i & &quot;']/telephone&quot;).text
msgbox html


Your problem is on this line:
html = nodes.item('telephone').text

The item collection takes only an integer. Since I don't like 'magic numbers', I prefer to use the selectSingleNode method with explicit element names.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top