473,320 Members | 2,048 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,320 software developers and data experts.

XPath attrbute issue


Hi,

Say I have the following xml, below, and would like to get the second <bar>
element with the following xpath expression "/foo/bar[i='1' and j='2']". This
only works if the 'i' attribute value differs from the first and second bar
element - why?
I can't see any ambiguity issues.

<foo>
<bar i='1'/>
<bar i='1' j='2'/>
</foo>
Apr 4 '07 #1
1 2066
Jesper wrote:
Say I have the following xml, below, and would like to get the second <bar>
element with the following xpath expression "/foo/bar[i='1' and j='2']". This
only works if the 'i' attribute value differs from the first and second bar
element - why?
I can't see any ambiguity issues.

<foo>
<bar i='1'/>
<bar i='1' j='2'/>
</foo>
Attribute nodes are selected with @attribute-name e.g.
/foo/bar[@i = '1' and @j = '2']
Using that I don't have any problems to find the second bar element, C#
sample program code is

string xmlMarkup = @"<foo>
<bar i='1'/>
<bar i='1' j='2'/>
</foo>";
XmlDocument xmlDocument = new XmlDocument();
xmlDocument.LoadXml(xmlMarkup);
XmlNode node = xmlDocument.SelectSingleNode(
@"/foo/bar[@i = '1' and @j = '2']");
if (node != null) {
Console.WriteLine("Found " + node.OuterXml);
}
else {
Console.WriteLine("No node found.");
}

which outputs

Found <bar i="1" j="2" />
--

Martin Honnen --- MVP XML
http://JavaScript.FAQTs.com/
Apr 4 '07 #2

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

Similar topics

5
by: Tom Alsberg | last post by:
Hi there... I'm recently trying to get a bit acquainted with XML Schemas and XSL. Now, I have a few questions about XSL stylesheets and templates: * Is there a way to "enter" a child element...
7
by: Ot | last post by:
I posted this to the wrong group. It went to m.p.dotnet.languages.vb. Ooops. -------------------------------------------------------------------- I have this tiny problem. I have learned...
4
by: Bnaya Eshet | last post by:
I do like XPath, I really do. But I'm working on the compact framework which XPath is not included. So I come to understanding that if XPath do not come to the mountain,
1
by: Rob | last post by:
Hi, I am moving through an XML document using an XPath Navigator, and I'd like to be able to get the xpath expression for the location of the current node from the root node. Any ideas how to...
3
by: bruce | last post by:
for guys with python/xpath expertise.. i'm playing with xpath.. and i'm trying to solve an issue... i have the following kind of situation where i'm trying to get certain data. i have a...
3
by: werD | last post by:
Hello I have an xml document that im currently using a forward only .net repeater on and using some xpath queries to display the data The xml is quite simple <?xml version="1.0"...
2
by: dba123 | last post by:
I have an issue where I want to put an image right before the text for each record below in a GridView. The problem is, the XPath is rss/channel/item". So since I have the picture in my XML file...
6
by: J.Marsch | last post by:
I must be completely losing my mind. I have some code that writes to config files. It works great with app.config files, but fails miserably with web.config files. For the life of me, I cannot...
1
by: bruce | last post by:
Hi. Got a test web page, that basically has two "<html" tags in it. Examining the page via Firefox/Dom Inspector, I can create a test xpath query "/html/body/form" which gets the target form for...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
0
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
0
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

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.