469,289 Members | 2,090 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,289 developers. It's quick & easy.

Using XPath with VB.NET

Hi, I have the following XML

<TREENODES>
<TREENODE TEXT="Car_1" ID="A1">
<TREENODE TEXT="Spoilers_1" ID="A1_1" />
<TREENODE TEXT="Spoilers_2" ID="A1_2" />
</TREENODE>
<TREENODE TEXT="Car_2" ID="B1" />
<TREENODE TEXT="Car_3" ID="C1">
<TREENODE TEXT="Spoilers_1" ID="C1_1" />
<TREENODE TEXT="Spoilers_2" ID="C1_2" />
</TREENODE>
....... 'Other XML nodes
</TREENODES>
I have the above XML document (I know that naming of the
nodes are so bad...) I need to find the specific node with
the exact ID, say ID=A1. Now, is it possible to use XPath
to find that node right away without looping thru the
whole thing... I am just curious..
Thanks
Carl
Nov 12 '05 #1
6 9001
Use this xpath expression in the SelectNodes or
SelectSingleNode function.

/TREENODES/TREENODE[@ID='A1']

Sonu Kapoor
blog: http://weblogs.asp.net/sonukapoor/

-----Original Message-----
Hi, I have the following XML

<TREENODES>
<TREENODE TEXT="Car_1" ID="A1">
<TREENODE TEXT="Spoilers_1" ID="A1_1" />
<TREENODE TEXT="Spoilers_2" ID="A1_2" />
</TREENODE>
<TREENODE TEXT="Car_2" ID="B1" />
<TREENODE TEXT="Car_3" ID="C1">
<TREENODE TEXT="Spoilers_1" ID="C1_1" />
<TREENODE TEXT="Spoilers_2" ID="C1_2" />
</TREENODE>
....... 'Other XML nodes
</TREENODES>
I have the above XML document (I know that naming of the
nodes are so bad...) I need to find the specific node withthe exact ID, say ID=A1. Now, is it possible to use XPath
to find that node right away without looping thru the
whole thing... I am just curious..
Thanks
Carl
.

Nov 12 '05 #2
Use this xpath expression in the SelectNodes or
SelectSingleNode function.

/TREENODES/TREENODE[@ID='A1']

Sonu Kapoor
blog: http://weblogs.asp.net/sonukapoor/

-----Original Message-----
Hi, I have the following XML

<TREENODES>
<TREENODE TEXT="Car_1" ID="A1">
<TREENODE TEXT="Spoilers_1" ID="A1_1" />
<TREENODE TEXT="Spoilers_2" ID="A1_2" />
</TREENODE>
<TREENODE TEXT="Car_2" ID="B1" />
<TREENODE TEXT="Car_3" ID="C1">
<TREENODE TEXT="Spoilers_1" ID="C1_1" />
<TREENODE TEXT="Spoilers_2" ID="C1_2" />
</TREENODE>
....... 'Other XML nodes
</TREENODES>
I have the above XML document (I know that naming of the
nodes are so bad...) I need to find the specific node withthe exact ID, say ID=A1. Now, is it possible to use XPath
to find that node right away without looping thru the
whole thing... I am just curious..
Thanks
Carl
.

Nov 12 '05 #3
Thanks Steve, Now. what if the xml now has more than 2
levels that I need to search for? I couldn't use syntax
like "/TREENODES/TREENODE[@ID='A1']" anymore. And I tried
somthing like "//TREENODE[@ID='A1']" but it won't work.
Can you tell me??
<TREENODES>
<TREENODE TEXT="My House" ID="H1">
<TREENODE TEXT="My Garage" ID="G1">
<TREENODE TEXT="Car_1" ID="A1">
<TREENODE TEXT="Spoilers_1" ID="A1_1" />
<TREENODE TEXT="Spoilers_2" ID="A1_2" />
</TREENODE>
<TREENODE TEXT="Car_2" ID="B1" />
<TREENODE TEXT="Car_3" ID="C1">
<TREENODE TEXT="Spoilers_1" ID="C1_1" />
<TREENODE TEXT="Spoilers_2" ID="C1_2" />
</TREENODE>
</TREENODE>
</TREENODE>
....... 'Other XML nodes
</TREENODES>
-----Original Message-----
Use this xpath expression in the SelectNodes or
SelectSingleNode function.

/TREENODES/TREENODE[@ID='A1']

Sonu Kapoor
blog: http://weblogs.asp.net/sonukapoor/

-----Original Message-----
Hi, I have the following XML

<TREENODES>
<TREENODE TEXT="Car_1" ID="A1">
<TREENODE TEXT="Spoilers_1" ID="A1_1" />
<TREENODE TEXT="Spoilers_2" ID="A1_2" />
</TREENODE>
<TREENODE TEXT="Car_2" ID="B1" />
<TREENODE TEXT="Car_3" ID="C1">
<TREENODE TEXT="Spoilers_1" ID="C1_1" />
<TREENODE TEXT="Spoilers_2" ID="C1_2" />
</TREENODE>
....... 'Other XML nodes
</TREENODES>
I have the above XML document (I know that naming of the
nodes are so bad...) I need to find the specific node

with
the exact ID, say ID=A1. Now, is it possible to use XPathto find that node right away without looping thru the
whole thing... I am just curious..
Thanks
Carl
.

.

Nov 12 '05 #4
Thanks Steve, Now. what if the xml now has more than 2
levels that I need to search for? I couldn't use syntax
like "/TREENODES/TREENODE[@ID='A1']" anymore. And I tried
somthing like "//TREENODE[@ID='A1']" but it won't work.
Can you tell me??
<TREENODES>
<TREENODE TEXT="My House" ID="H1">
<TREENODE TEXT="My Garage" ID="G1">
<TREENODE TEXT="Car_1" ID="A1">
<TREENODE TEXT="Spoilers_1" ID="A1_1" />
<TREENODE TEXT="Spoilers_2" ID="A1_2" />
</TREENODE>
<TREENODE TEXT="Car_2" ID="B1" />
<TREENODE TEXT="Car_3" ID="C1">
<TREENODE TEXT="Spoilers_1" ID="C1_1" />
<TREENODE TEXT="Spoilers_2" ID="C1_2" />
</TREENODE>
</TREENODE>
</TREENODE>
....... 'Other XML nodes
</TREENODES>
-----Original Message-----
Use this xpath expression in the SelectNodes or
SelectSingleNode function.

/TREENODES/TREENODE[@ID='A1']

Sonu Kapoor
blog: http://weblogs.asp.net/sonukapoor/

-----Original Message-----
Hi, I have the following XML

<TREENODES>
<TREENODE TEXT="Car_1" ID="A1">
<TREENODE TEXT="Spoilers_1" ID="A1_1" />
<TREENODE TEXT="Spoilers_2" ID="A1_2" />
</TREENODE>
<TREENODE TEXT="Car_2" ID="B1" />
<TREENODE TEXT="Car_3" ID="C1">
<TREENODE TEXT="Spoilers_1" ID="C1_1" />
<TREENODE TEXT="Spoilers_2" ID="C1_2" />
</TREENODE>
....... 'Other XML nodes
</TREENODES>
I have the above XML document (I know that naming of the
nodes are so bad...) I need to find the specific node

with
the exact ID, say ID=A1. Now, is it possible to use XPathto find that node right away without looping thru the
whole thing... I am just curious..
Thanks
Carl
.

.

Nov 12 '05 #5
Steve??

You could use an "AND" statement between the xpath's.
Something like this:

/TREENODES/TREENODE[@ID='A1'] AND /TREENODES/TREENODE
[@ID='B1']

Maybe its better to change the XML structure.

Sonu
-----Original Message-----
Thanks Steve, Now. what if the xml now has more than 2
levels that I need to search for? I couldn't use syntax
like "/TREENODES/TREENODE[@ID='A1']" anymore. And I tried
somthing like "//TREENODE[@ID='A1']" but it won't work.
Can you tell me??
<TREENODES>
<TREENODE TEXT="My House" ID="H1">
<TREENODE TEXT="My Garage" ID="G1">
<TREENODE TEXT="Car_1" ID="A1">
<TREENODE TEXT="Spoilers_1" ID="A1_1" />
<TREENODE TEXT="Spoilers_2" ID="A1_2" />
</TREENODE>
<TREENODE TEXT="Car_2" ID="B1" />
<TREENODE TEXT="Car_3" ID="C1">
<TREENODE TEXT="Spoilers_1" ID="C1_1" />
<TREENODE TEXT="Spoilers_2" ID="C1_2" />
</TREENODE>
</TREENODE>
</TREENODE>
....... 'Other XML nodes
</TREENODES>
-----Original Message-----
Use this xpath expression in the SelectNodes or
SelectSingleNode function.

/TREENODES/TREENODE[@ID='A1']

Sonu Kapoor
blog: http://weblogs.asp.net/sonukapoor/

-----Original Message-----
Hi, I have the following XML

<TREENODES>
<TREENODE TEXT="Car_1" ID="A1">
<TREENODE TEXT="Spoilers_1" ID="A1_1" />
<TREENODE TEXT="Spoilers_2" ID="A1_2" />
</TREENODE>
<TREENODE TEXT="Car_2" ID="B1" />
<TREENODE TEXT="Car_3" ID="C1">
<TREENODE TEXT="Spoilers_1" ID="C1_1" />
<TREENODE TEXT="Spoilers_2" ID="C1_2" />
</TREENODE>
....... 'Other XML nodes
</TREENODES>
I have the above XML document (I know that naming of thenodes are so bad...) I need to find the specific node

with
the exact ID, say ID=A1. Now, is it possible to useXPathto find that node right away without looping thru the
whole thing... I am just curious..
Thanks
Carl
.

.

.

Nov 12 '05 #6
Steve??

You could use an "AND" statement between the xpath's.
Something like this:

/TREENODES/TREENODE[@ID='A1'] AND /TREENODES/TREENODE
[@ID='B1']

Maybe its better to change the XML structure.

Sonu
-----Original Message-----
Thanks Steve, Now. what if the xml now has more than 2
levels that I need to search for? I couldn't use syntax
like "/TREENODES/TREENODE[@ID='A1']" anymore. And I tried
somthing like "//TREENODE[@ID='A1']" but it won't work.
Can you tell me??
<TREENODES>
<TREENODE TEXT="My House" ID="H1">
<TREENODE TEXT="My Garage" ID="G1">
<TREENODE TEXT="Car_1" ID="A1">
<TREENODE TEXT="Spoilers_1" ID="A1_1" />
<TREENODE TEXT="Spoilers_2" ID="A1_2" />
</TREENODE>
<TREENODE TEXT="Car_2" ID="B1" />
<TREENODE TEXT="Car_3" ID="C1">
<TREENODE TEXT="Spoilers_1" ID="C1_1" />
<TREENODE TEXT="Spoilers_2" ID="C1_2" />
</TREENODE>
</TREENODE>
</TREENODE>
....... 'Other XML nodes
</TREENODES>
-----Original Message-----
Use this xpath expression in the SelectNodes or
SelectSingleNode function.

/TREENODES/TREENODE[@ID='A1']

Sonu Kapoor
blog: http://weblogs.asp.net/sonukapoor/

-----Original Message-----
Hi, I have the following XML

<TREENODES>
<TREENODE TEXT="Car_1" ID="A1">
<TREENODE TEXT="Spoilers_1" ID="A1_1" />
<TREENODE TEXT="Spoilers_2" ID="A1_2" />
</TREENODE>
<TREENODE TEXT="Car_2" ID="B1" />
<TREENODE TEXT="Car_3" ID="C1">
<TREENODE TEXT="Spoilers_1" ID="C1_1" />
<TREENODE TEXT="Spoilers_2" ID="C1_2" />
</TREENODE>
....... 'Other XML nodes
</TREENODES>
I have the above XML document (I know that naming of thenodes are so bad...) I need to find the specific node

with
the exact ID, say ID=A1. Now, is it possible to useXPathto find that node right away without looping thru the
whole thing... I am just curious..
Thanks
Carl
.

.

.

Nov 12 '05 #7

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

reply views Thread by bdinmstig | last post: by
1 post views Thread by bdinmstig | last post: by
6 posts views Thread by 0wl | last post: by
2 posts views Thread by ree32 | last post: by
3 posts views Thread by Yair Cohen | last post: by
4 posts views Thread by syed.akhlaq | last post: by
1 post views Thread by CARIGAR | last post: by
reply views Thread by zhoujie | last post: by
reply views Thread by suresh191 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.