Hello,
I'm in trouble with a simple XPath expression. I've got the following
XML file
<?xml version="1.0" encoding="UTF-8"?>
<a>
<b>
<c>A</c>
</b>
<b>
<c>B</c>
</b>
<b>
<c>C</c>
</b>
<b>
<c>D</c>
<c>E</c>
<c>F</c>
<c>G</c>
</b>
</a>
and I'd like to reference the c-element with content B, i.e. the
second c-element in the file. But when I execute a/b/c[2], I get the c-
element with content E (the fifth one). Can somebody give me a hint in
what is wrong with this expression. In my opinion, at first a/b/c is
evaluated, which give a set of 7 nodes (7 c-element). Out of this set
the second node is taken, which would be the c-element with content B.
Best regards,
Sascha 4 2325
In article <11*********************@o80g2000hse.googlegroups. com>,
piramido <pi******@googlemail.comwrote:
>and I'd like to reference the c-element with content B, i.e. the second c-element in the file. But when I execute a/b/c[2], I get the c- element with content E (the fifth one). Can somebody give me a hint in what is wrong with this expression. In my opinion, at first a/b/c is evaluated, which give a set of 7 nodes (7 c-element). Out of this set the second node is taken, which would be the c-element with content B.
That's not how it works. You don't get the second node of a/b/c;
you get the c[2] of a/b. Only the fourth a/b has a c[2], and that's
the one you get.
(a/b/c)[2] will select the right element.
-- Richard
--
"Consideration shall be given to the need for as many as 32 characters
in some alphabets" - X3.4, 1963.
Richard Tobin a écrit :
In article <11*********************@o80g2000hse.googlegroups. com>,
piramido <pi******@googlemail.comwrote:
>and I'd like to reference the c-element with content B, i.e. the second c-element in the file. But when I execute a/b/c[2], I get the c- element with content E (the fifth one). Can somebody give me a hint in what is wrong with this expression. In my opinion, at first a/b/c is evaluated, which give a set of 7 nodes (7 c-element). Out of this set the second node is taken, which would be the c-element with content B.
That's not how it works. You don't get the second node of a/b/c;
you get the c[2] of a/b. Only the fourth a/b has a c[2], and that's
the one you get.
and a/b/c[1] will give you the 4 c elements that contain A B C D : you
evaluate a step upon the result of the previous one ; but as Richard
shows you, () are used for grouping
>
(a/b/c)[2] will select the right element.
-- Richard
--
Cordialement,
///
(. .)
--------ooO--(_)--Ooo--------
| Philippe Poulard |
----------------------------- http://reflex.gforge.inria.fr/
Have the RefleX !
Have a look at Xml Studio, it has a free XPath visualiser. http://www.liquid-technologies.com/P...nShots.aspx?11
On 29 Oct, 02:01, piramido <piram...@googlemail.comwrote:
Hello,
I'm in trouble with a simple XPath expression. I've got the following
XML file
<?xml version="1.0" encoding="UTF-8"?>
<a>
<b>
<c>A</c>
</b>
<b>
<c>B</c>
</b>
<b>
<c>C</c>
</b>
<b>
<c>D</c>
<c>E</c>
<c>F</c>
<c>G</c>
</b>
</a>
and I'd like to reference the c-element with content B, i.e. the
second c-element in the file. But when I execute a/b/c[2], I get the c-
element with content E (the fifth one). Can somebody give me a hint in
what is wrong with this expression. In my opinion, at first a/b/c is
evaluated, which give a set of 7 nodes (7 c-element). Out of this set
the second node is taken, which would be the c-element with content B.
Best regards,
Sascha
Hello Richard,
it works. Thank you so much!
Kind regards,
Sascha This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
by: inquirydog |
last post by:
Hi-
One frusterating thing for me with xsl is that I don't know
how to make xslt throw some sort of exception when a value-of path
does not exist. For instance, suppose I have the following...
|
by: gimme_this_gimme_that |
last post by:
I once downloaded a shareware program that allowed you
to open an xml file, click on a text or an attribute,
an then see the xpath expression that would fetch
that data.
The program didn't...
|
by: steve bull |
last post by:
I have the following code snippet to read the colorRange attributes for the colorRangeSwatch in the xml file listed
below.
string expr = "/swatches/colorRangeSwatch/colorRange";...
|
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 -...
|
by: laks |
last post by:
Hi
I have the following xsl stmt.
<xsl:for-each select="JOB_POSTINGS/JOB_POSTING
\">
<xsl:sort select="JOB_TITLE" order="ascending"/>
This works fine when I use it.
But when using multiple...
|
by: David Thielen |
last post by:
Hi;
I set up my xml as follows:
XmlDocument xml = new XmlDocument();
xml.Load(File.Open("data.xml", FileMode.Open, FileAccess.Read));
XmlNamespaceManager context = new...
|
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>
|
by: syed.akhlaq |
last post by:
Hi,
Does anyone know how can I validate XPath expressions using xsd
schema?
Thanks
|
by: arunairs |
last post by:
Hi,
Is there a way of validating and XPath? In this case , I am
accepting an XPath from the user and I need to validate the XPath
syntax. Is there a regular expression available that anyone can...
|
by: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
by: ryjfgjl |
last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
|
by: Sonnysonu |
last post by:
This is the data of csv file
1 2 3
1 2 3
1 2 3
1 2 3
2 3
2 3
3
the lengths should be different i have to store the data by column-wise with in the specific length.
suppose the i have to...
|
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...
|
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,...
|
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...
|
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,...
|
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...
|
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,...
| |