473,545 Members | 2,113 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 9105
Use this xpath expression in the SelectNodes or
SelectSingleNod e 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
SelectSingleNod e 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
SelectSingleNo de 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
SelectSingleNo de 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
SelectSingleN ode 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
SelectSingleN ode 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
1808
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 are stored in a free-format XML document (in memory for the life of the session) and persisted to a database (as free text) on exit. I have taught...
1
6813
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 elements, attributes, ".", and "..", plus also the "" predicate format is supported - however, only one predicate per path step is supported, and expr must...
6
5961
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 doc=parseString(xmlstr) nodeList = xml.xpath.Evaluate("/p:root/p:child/text()", doc)
0
1710
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" elementFormDefault="qualified" attributeFormDefault="unqualified"> <xs:element name="Loan"> <xs:complexType> <xs:sequence> <xs:element...
2
2866
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 - "xmlns="http://tempuri.org/nameOfRoot.xsd" I have no idea what its pointing to & what is tempuri.org? So when this tag is in my xml tag my xpath query never works. But...
3
2865
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 this ? using xmlDocument.documentElement.selectNodes("PROP") something like this:
3
6780
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> </Root> I would like to retreive "\Root\Customer\Name" out of it. Something like:
3
9157
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 really had any success. I'm pretty sure I should be casting my XPathSelect() call to something so I can get at its attributes. This seems like it...
4
9107
by: syed.akhlaq | last post by:
Hi, Does anyone know how can I validate XPath expressions using xsd schema? Thanks
5
6023
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 than this but for simplicity's sake, I've trimmed it down to this. The problem I'm running into is I want to find the best way to add the data into...
0
7468
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main...
0
7656
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. ...
0
7808
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
0
5972
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
1
5329
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes...
0
4945
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 then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert...
0
3450
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 last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in...
1
1884
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
1
1014
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.