473,545 Members | 937 Online
Bytes | Software Development & Data Engineering Community
+ 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(X MLLocation);
XPathNavigator nav = Doc.CreateNavig ator();
XPathNodeIterat or ni = nav.Select(??? XPathExpression ???);

Thanks.
Nov 12 '05 #1
4 1150
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='Microsof t']
etc.

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

Greatm thanks!
"Oleg Tkachenko [MVP]" <oleg@NO!SPAM!P LEASEtkachenko. com> wrote in message
news:%2******** ********@TK2MSF TNGP14.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='Microsof t']
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******** ******@TK2MSFTN GP09.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
2162
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 is particular usefull to be bind to a treeview as it handle nodes. So I have try to save my dataset content into a xml file. The content of that file...
2
2754
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 XPathNodeIterators with the same expression creates a coupling between the iterators so they always point to the same position. Anyone care to comment? ...
3
3892
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 before the /book tag?
1
1049
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"> <chapter> <title>Chapter 1</title> <starting_page>34</starting_page> <number_of_pages>15</number_of_pages> </chapter>
4
4495
by: viditmittal | last post by:
hi, i have a xml file <root> <Type /> <Description /> <Category /> <employee > <id>3</id>
6
15492
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
1043
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 xpathexpression. Because I have a namespace in the xml, I have to use the xmlNameSpaceManager and comile an xpathquery as below:
0
850
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 & "") dim ni as System.Xml.XPath.XPathNodeIterator = xpn.Select(expr) ni.MoveNext() if ni.Current.Value <> "" then
2
2313
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
7401
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language...
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
7807
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...
1
7419
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
0
7756
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
0
4944
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
3442
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
1879
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
0
703
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...

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.