473,473 Members | 1,581 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

Help with XPathExpression, please.

Hi, from an XML beginner..

I have an XML like the one below:

<root>
<vendor name="Microsoft">
<!-- additional sub-tags and items -->
</vendor>
<vendor name="Sun">
<!-- additional sub-tags and items -->
</vendor>
<vendor name="Borland">
<!-- additional sub-tags and items -->
</vendor>
</root>

Now, what's the correct XPathExpression to select only one vendor, let's say
Microsoft (in the code below)...?

XPathDocument Doc = new XPathDocument(XMLLocation);
XPathNavigator nav = Doc.CreateNavigator();
XPathNodeIterator ni = nav.Select(??? XPathExpression ???);

Thanks.
Nov 12 '05 #1
4 1142
gajba wrote:
I have an XML like the one below:

<root>
<vendor name="Microsoft">
<!-- additional sub-tags and items -->
</vendor>
<vendor name="Sun">
<!-- additional sub-tags and items -->
</vendor>
<vendor name="Borland">
<!-- additional sub-tags and items -->
</vendor>
</root>

Now, what's the correct XPathExpression to select only one vendor, let's say
Microsoft (in the code below)...?


To select first one use
/root/vendor[1]
To select Microsoft use
/root/vendor[@name='Microsoft']
etc.

--
Oleg Tkachenko [XML MVP]
http://blog.tkachenko.com
Nov 12 '05 #2
Oleg,

Greatm thanks!
"Oleg Tkachenko [MVP]" <oleg@NO!SPAM!PLEASEtkachenko.com> wrote in message
news:%2****************@TK2MSFTNGP14.phx.gbl...
gajba wrote:
I have an XML like the one below:

<root>
<vendor name="Microsoft">
<!-- additional sub-tags and items -->
</vendor>
<vendor name="Sun">
<!-- additional sub-tags and items -->
</vendor>
<vendor name="Borland">
<!-- additional sub-tags and items -->
</vendor>
</root>

Now, what's the correct XPathExpression to select only one vendor, let's say Microsoft (in the code below)...?


To select first one use
/root/vendor[1]
To select Microsoft use
/root/vendor[@name='Microsoft']
etc.

--
Oleg Tkachenko [XML MVP]
http://blog.tkachenko.com

Nov 12 '05 #3
Oleg, ... and I thought I would know what do next. Please, another
question:

If sub nodes of vendor "Microsoft" look like

<vendor name="Microsoft">
<NodeA>ValueA</NodeA>
<NodeB>ValueB</NodeB>
<NodeC>ValueC</NodeC>
</vendor>

How do I collect ValueA, ValueB and ValueC?

Nov 12 '05 #4
Solved!
"gajba" <ss************@sf.hr> wrote in message
news:O6**************@TK2MSFTNGP09.phx.gbl...
Oleg, ... and I thought I would know what do next. Please, another
question:

If sub nodes of vendor "Microsoft" look like

<vendor name="Microsoft">
<NodeA>ValueA</NodeA>
<NodeB>ValueB</NodeB>
<NodeC>ValueC</NodeC>
</vendor>

How do I collect ValueA, ValueB and ValueC?

Nov 12 '05 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: serge calderara | last post by:
Dear all, I have a csv file data which has been read and populate on a dataset object. then I need to bind part of the content of the dataset to a treeview control. I have read that XML format...
2
by: Steve Taylor | last post by:
Is there some reason why I shouldn't be able to use the same XPathExpression simultaneously in multiple iterations? The test below illustrates the problem. It seems that creating two...
3
by: ree32 | last post by:
Is there one? Also in either xpath or XPathExpression whats the best way to get the full xpath of a node. As i am using xpath query of (//books/.......) So I would like to see what is...
1
by: David | last post by:
I'm new to XML, so please bear with me. I'm using XPathNavigator and XPathNodeIterator to return a set of xml nodes from a document that looks like this: <root> <book title="Some Title">...
4
by: viditmittal | last post by:
hi, i have a xml file <root> <Type /> <Description /> <Category /> <employee > <id>3</id>
6
by: Chua Wen Ching | last post by:
Hi there, I had this xml file with me (not yet consider implementing xml namespaces yet). <?xml version='1.0'?> <Object> <Windows> <EID>1</EID> <EDesc>Error 1</EDesc> </Windows>
0
by: LockyBoy | last post by:
Hi Have created an xml document with an xmltextwriter with a namespace, so it can be validated against an xsd schema. Later in my application, I want to extract values from the xml and am using...
0
by: darrel | last post by:
I have a function that I pass some variables to, that then goes into an XML file and returns some other values: dim expr as System.Xml.XPath.XPathExpression = xpn.Compile("//" & variableToReturn...
2
by: darrel | last post by:
I have an XML file that looks like this: <Counties> <County> <District>2</District> <CountyName>Palm</CountyName> </County> <County> <District>3</District> <CountyName>McCarthy</CountyName>
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,...
1
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...
0
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,...
1
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
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
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
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?

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.