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

xpath help

Status
Not open for further replies.

BioMash

Programmer
Joined
Jan 29, 2002
Messages
2
Location
AU
I have an xmlnodelist bound to a datalist. I can access root elements in the list but can't figure out how to get a child of a child. I know I should use xpath but can not seem to get it to work.
At the moment i can get root elements:

<%#(CType(Container.DataItem, System.XML.XMLNode))("low").InnerText%>

but i need to select the innertext of grandchild element "t" of a child element "part" that has a p attribute of "d"

this is what i have at the moment but it doesn't work:

<%#(CType(Container.DataItem.SelectSingleNode, System.XML.XMLNode))("part[@p=d]/t").InnerText%>

<----begin xml document
<day d="0" t="Saturday" dt="Feb 28">
<hi>30</hi>
<low>22</low>
<sunr>6:05 AM</sunr>
<suns>6:54 PM</suns>
<part p="d">
<icon>32</icon>
<t>Sunny</t> <----------------want to display this text
<wind>
<s>23</s>
<gust>N/A</gust>
<d>166</d>
<t>SSE</t>
</wind>
<ppcp>0</ppcp>
<hmid>48</hmid>
</part>
<part p="n">
<icon>31</icon>
<t>Clear</t>
<wind>
<s>21</s>
<gust>N/A</gust>
<d>124</d>
<t>SE</t>
</wind>
<ppcp>0</ppcp>
<hmid>61</hmid>
</part>
</day>

Any help would be greatly appreciated
 
I thought the x-path-expression should be the complete path,
so:
day/part[@p=d]/t
or
//part[@p=d]/t
but maybe I'm wrong there.
Apart from that: if d is a value (not a node), you should use quotes:
part[@p='d']/t

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top