473,503 Members | 1,701 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 9103
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
1804
by: bdinmstig | last post by:
I am building various framework components for my team to use in development, and one of those components is a Facade for reading/writing user preferences. The idea is that preference settings...
1
6812
by: bdinmstig | last post by:
I refined my attempt a little further, and the following code does seem to work, however it has 2 major problems: 1. Very limited support for XPath features Basic paths are supported for...
6
5957
by: 0wl | last post by:
Hi, I am trying to get the value of child from xmlstr = """<p:root xmlns:p="http://tempuri.org/string"><p:child DataType="String">Hellpppp</p:child></p:root>""" using...
0
1705
by: Rajesh Jain | last post by:
I Have 2 separate schemas. --------------Schema 1 is defined as below----------- <xs:schema targetNamespace="http://Schemas/1" xmlns="http://Schemas/1" xmlns:xs="http://www.w3.org/2001/XMLSchema"...
2
2853
by: ree32 | last post by:
When I import an xml document in Visual studio and Genereate as schema from it, and create a dataset from it, it adds this line into to the root element of my xml file -...
3
2863
by: Yair Cohen | last post by:
hello 1 i use an xml documet with xml schema but when i try to use XPath (selectnodes) it retrieves empty list. when i remove the schema (the 'xmlns="http..."') i get the data. how can i handle...
3
6772
by: Goran Djuranovic | last post by:
Hi All, Does anyone know how to retreive deepest XPath value from XML document by using VB.NET? For example, if I had an XML file like this: <Root> <Customer> <Name>MyName</Name> </Customer>...
3
9154
by: Brian | last post by:
Using external XML, I'm trying to build a quiz, but I can't seem to specify the DataSource for the RadioButtonList within a Repeater ItemTemplate. I've tried a number of approaches, but I haven't...
4
9099
by: syed.akhlaq | last post by:
Hi, Does anyone know how can I validate XPath expressions using xsd schema? Thanks
5
6015
by: rcronk | last post by:
I'm new to C#/.NET. I am writing some C#/.NET (2.0) classes that will allow someone to get and set values in an XML file using an XPath to point to the location of that data. It's more complicated...
0
7074
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
7273
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
7322
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
6982
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
1
5000
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
4667
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
3161
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
3150
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
731
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.