473,387 Members | 1,721 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

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 9101
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
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
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
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
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
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
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
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
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
by: syed.akhlaq | last post by:
Hi, Does anyone know how can I validate XPath expressions using xsd schema? Thanks
5
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
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
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
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...

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.