473,387 Members | 1,463 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,387 software developers and data experts.

What am I doing wrong in this XPath expression?



I have the following code snippet to read the colorRange attributes for the colorRangeSwatch in the xml file listed
below.

string expr = "/swatches[colorRangeSwatch='All Red Colors']/colorRangeSwatch/colorRange";
XmlElement crsElement = (XmlElement)m_colorRangeSwatchDoc.SelectSingleNode (expr);
bool fr = bool.Parse(crsElement.GetAttribute("fixed").ToStri ng());
The element returned is always the 1st, All Blue Colors, why doesn't the expression filter on the colorRangeSwatch
value?

Any ideas would be welcome.

Thanks,

Steve

The xml file which I am trying to read from :

<?xml version="1.0" encoding="utf-8" standalone="no" ?>
<swatches id="CustomColorRangeSwatches">
<colorRangeSwatch>All Blue Colors
<colorRange fixed="True"
red="0" green="0" blue="193"
redMin="0" redMax="0"
greenMin="0" greenMax="0"
blueMin="0" blueMax="255" />
</colorRangeSwatch>
<colorRangeSwatch>All Red Colors
<colorRange fixed="True"
red="183" green="0" blue="0"
redMin="0" redMax="255"
greenMin="0" greenMax="0"
blueMin="0" blueMax="0" />
</colorRangeSwatch>
</swatches>

Jul 20 '05 #1
7 1790

"steve bull" <bu****@comcast.net> wrote in message
news:qh********************************@4ax.com...


I have the following code snippet to read the colorRange attributes for
the colorRangeSwatch in the xml file listed
below.

string expr = "/swatches[colorRangeSwatch='All Red
Colors']/colorRangeSwatch/colorRange";
XmlElement crsElement =
(XmlElement)m_colorRangeSwatchDoc.SelectSingleNode (expr);
bool fr =
bool.Parse(crsElement.GetAttribute("fixed").ToStri ng());
The element returned is always the 1st, All Blue Colors, why doesn't the
expression filter on the colorRangeSwatch
value?

Any ideas would be welcome.

Thanks,

Steve

The xml file which I am trying to read from :

<?xml version="1.0" encoding="utf-8" standalone="no" ?>
<swatches id="CustomColorRangeSwatches">
<colorRangeSwatch>All Blue Colors
<colorRange fixed="True"
red="0" green="0" blue="193"
redMin="0" redMax="0"
greenMin="0" greenMax="0"
blueMin="0" blueMax="255" />
</colorRangeSwatch>
<colorRangeSwatch>All Red Colors
<colorRange fixed="True"
red="183" green="0" blue="0"
redMin="0" redMax="255"
greenMin="0" greenMax="0"
blueMin="0" blueMax="0" />
</colorRangeSwatch>
</swatches>


There are at least three problems:

1. Your source xml is unreadable -- in case you really hope someone might
give it a try, provide a more readable version, maybe something like this:

<swatches id="CustomColorRangeSwatches">
<colorRangeSwatch>All Blue Colors
<colorRange fixed="True"
red="0" green="0" blue="193"
redMin="0" redMax="0"
greenMin="0" greenMax="0"
blueMin="0" blueMax="255" />
</colorRangeSwatch>
<colorRangeSwatch>All Red Colors
<colorRange fixed="True"
red="183" green="0" blue="0"
redMin="0" redMax="255"
greenMin="0" greenMax="0"
blueMin="0" blueMax="0" />
</colorRangeSwatch>
</swatches>

2. The comparison:
colorRangeSwatch='All Red Colors'
will most probably return false for the top node. There are some NL
characters after the starting text.

3. Most important:

/swatches[colorRangeSwatch='All Red
Colors']/colorRangeSwatch/colorRange
-------------------------------------------------------------^^^^^^^^^^^^^^^^^^^

Even if the comparison in the predicate returns true, the location
step following it selects *all* "colorRangeSwatch" elements children of the
top element "swatches"

Thus, if the comparison is trye, the expression above will select all
"colorRange" children of all "colorRangeSwatch" children of the top element
"swatches".

Then the SelectSingleNode() method returns the first in document order
such "colorRange" element -- and you say you want the second.
One XPath expression that will select the node you seem to want is:

/swatches/colorRangeSwatch[starts-with(.,'All Red Colors')]/colorRange

Hope this helped.
Cheers,
Dimitre Novatchev
Jul 20 '05 #2


Thanks, it works. I don't really understand why but it does appear to do what I want. It has been quite frustrating
trying to figure out the right syntax.

Apart from the xml header line I don't see a difference between the xml you returned and what I posted.
Many thanks,

Steve

On Sat, 18 Jun 2005 06:40:53 +1000, "Dimitre Novatchev" <di******@tpg.com.au> wrote:

"steve bull" <bu****@comcast.net> wrote in message
news:qh********************************@4ax.com.. .


I have the following code snippet to read the colorRange attributes for
the colorRangeSwatch in the xml file listed
below.

string expr = "/swatches[colorRangeSwatch='All Red
Colors']/colorRangeSwatch/colorRange";
XmlElement crsElement =
(XmlElement)m_colorRangeSwatchDoc.SelectSingleNode (expr);
bool fr =
bool.Parse(crsElement.GetAttribute("fixed").ToStri ng());
The element returned is always the 1st, All Blue Colors, why doesn't the
expression filter on the colorRangeSwatch
value?

Any ideas would be welcome.

Thanks,

Steve

The xml file which I am trying to read from :

<?xml version="1.0" encoding="utf-8" standalone="no" ?>
<swatches id="CustomColorRangeSwatches">
<colorRangeSwatch>All Blue Colors
<colorRange fixed="True"
red="0" green="0" blue="193"
redMin="0" redMax="0"
greenMin="0" greenMax="0"
blueMin="0" blueMax="255" />
</colorRangeSwatch>
<colorRangeSwatch>All Red Colors
<colorRange fixed="True"
red="183" green="0" blue="0"
redMin="0" redMax="255"
greenMin="0" greenMax="0"
blueMin="0" blueMax="0" />
</colorRangeSwatch>
</swatches>


There are at least three problems:

1. Your source xml is unreadable -- in case you really hope someone might
give it a try, provide a more readable version, maybe something like this:

<swatches id="CustomColorRangeSwatches">
<colorRangeSwatch>All Blue Colors
<colorRange fixed="True"
red="0" green="0" blue="193"
redMin="0" redMax="0"
greenMin="0" greenMax="0"
blueMin="0" blueMax="255" />
</colorRangeSwatch>
<colorRangeSwatch>All Red Colors
<colorRange fixed="True"
red="183" green="0" blue="0"
redMin="0" redMax="255"
greenMin="0" greenMax="0"
blueMin="0" blueMax="0" />
</colorRangeSwatch>
</swatches>

2. The comparison:
colorRangeSwatch='All Red Colors'
will most probably return false for the top node. There are some NL
characters after the starting text.

3. Most important:

/swatches[colorRangeSwatch='All Red
Colors']/colorRangeSwatch/colorRange
-------------------------------------------------------------^^^^^^^^^^^^^^^^^^^

Even if the comparison in the predicate returns true, the location
step following it selects *all* "colorRangeSwatch" elements children of the
top element "swatches"

Thus, if the comparison is trye, the expression above will select all
"colorRange" children of all "colorRangeSwatch" children of the top element
"swatches".

Then the SelectSingleNode() method returns the first in document order
such "colorRange" element -- and you say you want the second.
One XPath expression that will select the node you seem to want is:

/swatches/colorRangeSwatch[starts-with(.,'All Red Colors')]/colorRange

Hope this helped.
Cheers,
Dimitre Novatchev


Jul 20 '05 #3

"steve bull" <bu****@comcast.net> wrote in message
news:40********************************@4ax.com...


Thanks, it works. I don't really understand why but it does appear to do
what I want. It has been quite frustrating
trying to figure out the right syntax.

Apart from the xml header line I don't see a difference between the xml
you returned and what I posted.
Then it would be worthy to start learning XPath seriously.

Also, using a tool like the XPath Visualizer may prove helpful.
Cheers,
Dimitre Novatchev.



Many thanks,

Steve

On Sat, 18 Jun 2005 06:40:53 +1000, "Dimitre Novatchev"
<di******@tpg.com.au> wrote:

"steve bull" <bu****@comcast.net> wrote in message
news:qh********************************@4ax.com. ..


I have the following code snippet to read the colorRange attributes for
the colorRangeSwatch in the xml file listed
below.

string expr = "/swatches[colorRangeSwatch='All Red
Colors']/colorRangeSwatch/colorRange";
XmlElement crsElement =
(XmlElement)m_colorRangeSwatchDoc.SelectSingleNode (expr);
bool fr =
bool.Parse(crsElement.GetAttribute("fixed").ToStri ng());
The element returned is always the 1st, All Blue Colors, why doesn't the
expression filter on the colorRangeSwatch
value?

Any ideas would be welcome.

Thanks,

Steve

The xml file which I am trying to read from :

<?xml version="1.0" encoding="utf-8" standalone="no" ?>
<swatches id="CustomColorRangeSwatches">
<colorRangeSwatch>All Blue Colors
<colorRange fixed="True"
red="0" green="0" blue="193"
redMin="0" redMax="0"
greenMin="0" greenMax="0"
blueMin="0" blueMax="255" />
</colorRangeSwatch>
<colorRangeSwatch>All Red Colors
<colorRange fixed="True"
red="183" green="0" blue="0"
redMin="0" redMax="255"
greenMin="0" greenMax="0"
blueMin="0" blueMax="0" />
</colorRangeSwatch>
</swatches>


There are at least three problems:

1. Your source xml is unreadable -- in case you really hope someone
might
give it a try, provide a more readable version, maybe something like this:

<swatches id="CustomColorRangeSwatches">
<colorRangeSwatch>All Blue Colors
<colorRange fixed="True"
red="0" green="0" blue="193"
redMin="0" redMax="0"
greenMin="0" greenMax="0"
blueMin="0" blueMax="255" />
</colorRangeSwatch>
<colorRangeSwatch>All Red Colors
<colorRange fixed="True"
red="183" green="0" blue="0"
redMin="0" redMax="255"
greenMin="0" greenMax="0"
blueMin="0" blueMax="0" />
</colorRangeSwatch>
</swatches>

2. The comparison:
colorRangeSwatch='All Red Colors'
will most probably return false for the top node. There are some NL
characters after the starting text.

3. Most important:

/swatches[colorRangeSwatch='All Red
Colors']/colorRangeSwatch/colorRange
-------------------------------------------------------------^^^^^^^^^^^^^^^^^^^

Even if the comparison in the predicate returns true, the location
step following it selects *all* "colorRangeSwatch" elements children of
the
top element "swatches"

Thus, if the comparison is trye, the expression above will select all
"colorRange" children of all "colorRangeSwatch" children of the top
element
"swatches".

Then the SelectSingleNode() method returns the first in document order
such "colorRange" element -- and you say you want the second.
One XPath expression that will select the node you seem to want is:

/swatches/colorRangeSwatch[starts-with(.,'All Red Colors')]/colorRange

Hope this helped.
Cheers,
Dimitre Novatchev

Jul 20 '05 #4

"steve bull" <bu****@comcast.net> wrote in message
news:40********************************@4ax.com...


Thanks, it works. I don't really understand why but it does appear to do
what I want.
Your original XPath expression:
/swatches[colorRangeSwatch='All Red
Colors']/colorRangeSwatch/colorRange


has this translation into English:

Select all "colorRange" elements that are children of a "colorRangeSwatch"
element, which is a child of a top element named "swatches", if this top
element has children named "colorRangeSwatch", whose string value is 'All
Red Colors'

It selects the same nodes as this simpler expression because the condition
inside the predicate is true -- the top element satisfies the condition,
therefore all of its colorRangeSwatch/colorRange grand-children will be
selected:

/swatches/colorRangeSwatch/colorRange

But you wanted the colorRange nodes that are children only of the
colorRangeSwatch elements, whose string value starts with
'All Red Colors'

One XPath expression that returns the nodes you wanted is

/swatches/colorRangeSwatch[starts-with(.,'All Red Colors')]/colorRange

The translation of this into English is:

Select all "colorRange" elements, which are children of a "colorRangeSwatch"
element, whose string value starts with the string
'All Red Colors' and which is child of the top element named "swatches".
It has been quite frustrating
trying to figure out the right syntax.

Apart from the xml header line I don't see a difference between the xml
you returned and what I posted.
The difference is only in readability :o)



Many thanks,

Steve

On Sat, 18 Jun 2005 06:40:53 +1000, "Dimitre Novatchev"
<di******@tpg.com.au> wrote:

"steve bull" <bu****@comcast.net> wrote in message
news:qh********************************@4ax.com. ..


I have the following code snippet to read the colorRange attributes for
the colorRangeSwatch in the xml file listed
below.

string expr = "/swatches[colorRangeSwatch='All Red
Colors']/colorRangeSwatch/colorRange";
XmlElement crsElement =
(XmlElement)m_colorRangeSwatchDoc.SelectSingleNode (expr);
bool fr =
bool.Parse(crsElement.GetAttribute("fixed").ToStri ng());
The element returned is always the 1st, All Blue Colors, why doesn't the
expression filter on the colorRangeSwatch
value?

Any ideas would be welcome.

Thanks,

Steve

The xml file which I am trying to read from :

<?xml version="1.0" encoding="utf-8" standalone="no" ?>
<swatches id="CustomColorRangeSwatches">
<colorRangeSwatch>All Blue Colors
<colorRange fixed="True"
red="0" green="0" blue="193"
redMin="0" redMax="0"
greenMin="0" greenMax="0"
blueMin="0" blueMax="255" />
</colorRangeSwatch>
<colorRangeSwatch>All Red Colors
<colorRange fixed="True"
red="183" green="0" blue="0"
redMin="0" redMax="255"
greenMin="0" greenMax="0"
blueMin="0" blueMax="0" />
</colorRangeSwatch>
</swatches>


There are at least three problems:

1. Your source xml is unreadable -- in case you really hope someone
might
give it a try, provide a more readable version, maybe something like this:

<swatches id="CustomColorRangeSwatches">
<colorRangeSwatch>All Blue Colors
<colorRange fixed="True"
red="0" green="0" blue="193"
redMin="0" redMax="0"
greenMin="0" greenMax="0"
blueMin="0" blueMax="255" />
</colorRangeSwatch>
<colorRangeSwatch>All Red Colors
<colorRange fixed="True"
red="183" green="0" blue="0"
redMin="0" redMax="255"
greenMin="0" greenMax="0"
blueMin="0" blueMax="0" />
</colorRangeSwatch>
</swatches>

2. The comparison:
colorRangeSwatch='All Red Colors'
will most probably return false for the top node. There are some NL
characters after the starting text.

3. Most important:

/swatches[colorRangeSwatch='All Red
Colors']/colorRangeSwatch/colorRange
-------------------------------------------------------------^^^^^^^^^^^^^^^^^^^

Even if the comparison in the predicate returns true, the location
step following it selects *all* "colorRangeSwatch" elements children of
the
top element "swatches"

Thus, if the comparison is trye, the expression above will select all
"colorRange" children of all "colorRangeSwatch" children of the top
element
"swatches".

Then the SelectSingleNode() method returns the first in document order
such "colorRange" element -- and you say you want the second.
One XPath expression that will select the node you seem to want is:

/swatches/colorRangeSwatch[starts-with(.,'All Red Colors')]/colorRange

Hope this helped.
Cheers,
Dimitre Novatchev

Jul 20 '05 #5

Many thanks. I understand what is happening now. I tried quite a few sources for XPath but none of them were really
clear on what was happening in the selection process even though they had quite a few examples. I guess it is always
more difficult when you have to work out an example for the first time.

I hadn't really noticed the functions either. I am surprised though that there does not appear to be a function for
testing equality between two strings.

Thanks again,

Steve



On Sat, 18 Jun 2005 13:50:57 +1000, "Dimitre Novatchev" <di******@tpg.com.au> wrote:

"steve bull" <bu****@comcast.net> wrote in message
news:40********************************@4ax.com.. .


Thanks, it works. I don't really understand why but it does appear to do
what I want.


Your original XPath expression:
/swatches[colorRangeSwatch='All Red
Colors']/colorRangeSwatch/colorRange


has this translation into English:

Select all "colorRange" elements that are children of a "colorRangeSwatch"
element, which is a child of a top element named "swatches", if this top
element has children named "colorRangeSwatch", whose string value is 'All
Red Colors'

It selects the same nodes as this simpler expression because the condition
inside the predicate is true -- the top element satisfies the condition,
therefore all of its colorRangeSwatch/colorRange grand-children will be
selected:

/swatches/colorRangeSwatch/colorRange

But you wanted the colorRange nodes that are children only of the
colorRangeSwatch elements, whose string value starts with
'All Red Colors'

One XPath expression that returns the nodes you wanted is

/swatches/colorRangeSwatch[starts-with(.,'All Red Colors')]/colorRange

The translation of this into English is:

Select all "colorRange" elements, which are children of a "colorRangeSwatch"
element, whose string value starts with the string
'All Red Colors' and which is child of the top element named "swatches".
It has been quite frustrating
trying to figure out the right syntax.

Apart from the xml header line I don't see a difference between the xml
you returned and what I posted.


The difference is only in readability :o)



Many thanks,

Steve

On Sat, 18 Jun 2005 06:40:53 +1000, "Dimitre Novatchev"
<di******@tpg.com.au> wrote:

"steve bull" <bu****@comcast.net> wrote in message
news:qh********************************@4ax.com ...
I have the following code snippet to read the colorRange attributes for
the colorRangeSwatch in the xml file listed
below.

string expr = "/swatches[colorRangeSwatch='All Red
Colors']/colorRangeSwatch/colorRange";
XmlElement crsElement =
(XmlElement)m_colorRangeSwatchDoc.SelectSingleNode (expr);
bool fr =
bool.Parse(crsElement.GetAttribute("fixed").ToStri ng());
The element returned is always the 1st, All Blue Colors, why doesn't the
expression filter on the colorRangeSwatch
value?

Any ideas would be welcome.

Thanks,

Steve

The xml file which I am trying to read from :

<?xml version="1.0" encoding="utf-8" standalone="no" ?>
<swatches id="CustomColorRangeSwatches">
<colorRangeSwatch>All Blue Colors
<colorRange fixed="True"
red="0" green="0" blue="193"
redMin="0" redMax="0"
greenMin="0" greenMax="0"
blueMin="0" blueMax="255" />
</colorRangeSwatch>
<colorRangeSwatch>All Red Colors
<colorRange fixed="True"
red="183" green="0" blue="0"
redMin="0" redMax="255"
greenMin="0" greenMax="0"
blueMin="0" blueMax="0" />
</colorRangeSwatch>
</swatches>
There are at least three problems:

1. Your source xml is unreadable -- in case you really hope someone
might
give it a try, provide a more readable version, maybe something like this:

<swatches id="CustomColorRangeSwatches">
<colorRangeSwatch>All Blue Colors
<colorRange fixed="True"
red="0" green="0" blue="193"
redMin="0" redMax="0"
greenMin="0" greenMax="0"
blueMin="0" blueMax="255" />
</colorRangeSwatch>
<colorRangeSwatch>All Red Colors
<colorRange fixed="True"
red="183" green="0" blue="0"
redMin="0" redMax="255"
greenMin="0" greenMax="0"
blueMin="0" blueMax="0" />
</colorRangeSwatch>
</swatches>

2. The comparison:
colorRangeSwatch='All Red Colors'
will most probably return false for the top node. There are some NL
characters after the starting text.

3. Most important:

/swatches[colorRangeSwatch='All Red
Colors']/colorRangeSwatch/colorRange
-------------------------------------------------------------^^^^^^^^^^^^^^^^^^^

Even if the comparison in the predicate returns true, the location
step following it selects *all* "colorRangeSwatch" elements children of
the
top element "swatches"

Thus, if the comparison is trye, the expression above will select all
"colorRange" children of all "colorRangeSwatch" children of the top
element
"swatches".

Then the SelectSingleNode() method returns the first in document order
such "colorRange" element -- and you say you want the second.
One XPath expression that will select the node you seem to want is:

/swatches/colorRangeSwatch[starts-with(.,'All Red Colors')]/colorRange

Hope this helped.
Cheers,
Dimitre Novatchev


Jul 20 '05 #6
> I hadn't really noticed the functions either. I am surprised though that
there does not appear to be a function for
testing equality between two strings.
There isn't a "function" for comparing two strings, because this function is
the "=" operator.

the expression

str1 = str2,

where str1 and str2 are strings

is true iff the two strings are equal.

I used the starts-with() function, because in your xml file their were some
newline (NL) characters part of the text nodes.

Another way to eliminate unnecessary white space is to use the
normalize-space() function.
Cheers,
Dimitre Novatchev


"steve bull" <bu****@comcast.net> wrote in message
news:ct********************************@4ax.com...
Many thanks. I understand what is happening now. I tried quite a few
sources for XPath but none of them were really
clear on what was happening in the selection process even though they had
quite a few examples. I guess it is always
more difficult when you have to work out an example for the first time.

I hadn't really noticed the functions either. I am surprised though that
there does not appear to be a function for
testing equality between two strings.

Thanks again,

Steve



On Sat, 18 Jun 2005 13:50:57 +1000, "Dimitre Novatchev"
<di******@tpg.com.au> wrote:

"steve bull" <bu****@comcast.net> wrote in message
news:40********************************@4ax.com. ..


Thanks, it works. I don't really understand why but it does appear to do
what I want.


Your original XPath expression:
/swatches[colorRangeSwatch='All Red
Colors']/colorRangeSwatch/colorRange


has this translation into English:

Select all "colorRange" elements that are children of a "colorRangeSwatch"
element, which is a child of a top element named "swatches", if this top
element has children named "colorRangeSwatch", whose string value is 'All
Red Colors'

It selects the same nodes as this simpler expression because the condition
inside the predicate is true -- the top element satisfies the condition,
therefore all of its colorRangeSwatch/colorRange grand-children will be
selected:

/swatches/colorRangeSwatch/colorRange

But you wanted the colorRange nodes that are children only of the
colorRangeSwatch elements, whose string value starts with
'All Red Colors'

One XPath expression that returns the nodes you wanted is

/swatches/colorRangeSwatch[starts-with(.,'All Red
Colors')]/colorRange

The translation of this into English is:

Select all "colorRange" elements, which are children of a
"colorRangeSwatch"
element, whose string value starts with the string
'All Red Colors' and which is child of the top element named "swatches".
It has been quite frustrating
trying to figure out the right syntax.

Apart from the xml header line I don't see a difference between the xml
you returned and what I posted.


The difference is only in readability :o)



Many thanks,

Steve

On Sat, 18 Jun 2005 06:40:53 +1000, "Dimitre Novatchev"
<di******@tpg.com.au> wrote:
"steve bull" <bu****@comcast.net> wrote in message
news:qh********************************@4ax.co m...
>
>
> I have the following code snippet to read the colorRange attributes
> for
> the colorRangeSwatch in the xml file listed
> below.
>
> string expr = "/swatches[colorRangeSwatch='All Red
> Colors']/colorRangeSwatch/colorRange";
> XmlElement crsElement =
> (XmlElement)m_colorRangeSwatchDoc.SelectSingleNode (expr);
> bool fr =
> bool.Parse(crsElement.GetAttribute("fixed").ToStri ng());
>
>
> The element returned is always the 1st, All Blue Colors, why doesn't
> the
> expression filter on the colorRangeSwatch
> value?
>
> Any ideas would be welcome.
>
> Thanks,
>
> Steve
>
>
>
> The xml file which I am trying to read from :
>
> <?xml version="1.0" encoding="utf-8" standalone="no" ?>
> <swatches id="CustomColorRangeSwatches">
> <colorRangeSwatch>All Blue Colors
> <colorRange fixed="True"
> red="0" green="0" blue="193"
> redMin="0" redMax="0"
> greenMin="0" greenMax="0"
> blueMin="0" blueMax="255" />
> </colorRangeSwatch>
> <colorRangeSwatch>All Red Colors
> <colorRange fixed="True"
> red="183" green="0" blue="0"
> redMin="0" redMax="255"
> greenMin="0" greenMax="0"
> blueMin="0" blueMax="0" />
> </colorRangeSwatch>
> </swatches>
>

There are at least three problems:

1. Your source xml is unreadable -- in case you really hope someone
might
give it a try, provide a more readable version, maybe something like
this:

<swatches id="CustomColorRangeSwatches">
<colorRangeSwatch>All Blue Colors
<colorRange fixed="True"
red="0" green="0" blue="193"
redMin="0" redMax="0"
greenMin="0" greenMax="0"
blueMin="0" blueMax="255" />
</colorRangeSwatch>
<colorRangeSwatch>All Red Colors
<colorRange fixed="True"
red="183" green="0" blue="0"
redMin="0" redMax="255"
greenMin="0" greenMax="0"
blueMin="0" blueMax="0" />
</colorRangeSwatch>
</swatches>

2. The comparison:
colorRangeSwatch='All Red Colors'
will most probably return false for the top node. There are some
NL
characters after the starting text.

3. Most important:

/swatches[colorRangeSwatch='All Red
Colors']/colorRangeSwatch/colorRange
-------------------------------------------------------------^^^^^^^^^^^^^^^^^^^

Even if the comparison in the predicate returns true, the location
step following it selects *all* "colorRangeSwatch" elements children of
the
top element "swatches"

Thus, if the comparison is trye, the expression above will select
all
"colorRange" children of all "colorRangeSwatch" children of the top
element
"swatches".

Then the SelectSingleNode() method returns the first in document
order
such "colorRange" element -- and you say you want the second.
One XPath expression that will select the node you seem to want is:

/swatches/colorRangeSwatch[starts-with(.,'All Red
Colors')]/colorRange

Hope this helped.
Cheers,
Dimitre Novatchev

Jul 20 '05 #7

I hadn't really n oticed the functions either. I am surprised though
that there does not appear to be a function for testing equality between two strings.

You can just use = for that.

David
Jul 20 '05 #8

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

Similar topics

2
by: Steve Jorgensen | last post by:
Working with the DOM (specifically, the MSXML DOM), I'm wondering if there's an efficient way to check whether it would be matched by a given XPath expression. I've made it work to just run the...
1
by: Dave | last post by:
Is it possible to get <codes><code id="4"><name>abc</name></code></codes from the XML below in single SelectSingleNode/xPath expression step OR is going to have to be a multi=step process of...
2
by: gonzalez | last post by:
Hi, I'm trying to get the absolute xpath to a node in DOM (XmlDocument). I know I can build it by warlking the tree recursively, but I'm wondering if there is an API in DOM or in XPathNavigator...
2
by: steve bull | last post by:
I thought I had figured it out. But, I am only half way there. Now I have the following code snippet to read the colorRange attributes for the colorRangeSwatch in the xml file listed below. ...
3
by: richlm | last post by:
I use node.SelectNode(...) to locate a particular element/attribute in my document. If it doesn't exist I get a null reference. Is there a simple way to create the "missing" element/attribute...
0
by: KathyB | last post by:
Hi, I'm using the following xmlDocument and xpath to load a file using a variable. I've tried several renditions of the xpath using the variable but without success (error: object variable not...
3
by: abcd_68 | last post by:
Hi there, I'm using, for the first time, the JDK1.5 Xpath API. I need to find elements in a Hibernate-generated .hbm.xml file. These files come with a <!DOCTYPE header mentioning a remote URL....
17
by: Luc Mercier | last post by:
Hi Folks, I'm new here, and I need some advice for what tool to use. I'm using XML for benchmarking purposes. I'm writing some scientific programs which I want to analyze. My program generates...
2
by: Ty | last post by:
I have a data bound combo box. It is bound to a XML file. The XML file is structured like so, <Software> <Name>Test1</Name> <Name>Test1</Name> </Software> I set the Xpath expression in...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
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...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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
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...

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.