Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > Help with XPath query

Reply
Thread Tools

Help with XPath query

 
 
=?Utf-8?B?RGlmZmlkZW50?=
Guest
Posts: n/a
 
      03-05-2007
Hello All,

I am trying to construct an XPath query against an XML document, for a
requirement that I have. Below is the XML fragment:

<SUBMISSIONS>
<SUBMISSION YEAR="2004">
<MONTH NAME="JAN">10</MONTH>
<MONTH NAME="FEB">02</MONTH>
.
.
<MONTH NAME="DEC">78</MONTH>
</SUBMISSION>
<SUBMISSION YEAR="2005">
<MONTH NAME="JAN">03</MONTH>
<MONTH NAME="FEB">50</MONTH>
.
.
<MONTH NAME="DEC">27</MONTH>
</SUBMISSION>
<SUBMISSION YEAR="2006">
<MONTH NAME="JAN">34</MONTH>
<MONTH NAME="FEB">65</MONTH>
.
.
<MONTH NAME="DEC">22</MONTH>
</SUBMISSION>
<SUBMISSIONS>

If a user selects a time-period from 01-MAR-2005 to 31-DEC-2006, I have to
display month-wise counts for each of those months. i.e., I have to add March
of 2005 and March of 2006, April of 2005 and April of 2006 and so on and so
forth. and display the grand totals for individual months during that time
period. As part of this requirement, I wrote the following XPath query to get
the nodes for "NOV" from any of the years > 2005.

"/SUBMISSIONS/SUBMISSION[@YEAR >= 2005]/MONTH[@NAME='NOV']"

But what I really need is the time period from 2005 to 2006; and when I try
the below query to get the nodes between this time period, I get "invalid
token" error message:

"/SUBMISSIONS/SUBMISSION[@YEAR >= 2005 AND @YEAR <= 2006]/MONTH[@NAME='NOV']"

Is not this a valid Xpath query? Cannot I specify lower bound and upper
bound simultaneously in an Xpath query? If I give only one predicate it works
fine...

Help!!!!


 
Reply With Quote
 
 
 
 
bruce barker
Guest
Posts: n/a
 
      03-05-2007
xquery is case sensitive, use "and"

-- bruce (sqlwork.com)

Diffident wrote:
> Hello All,
>
> I am trying to construct an XPath query against an XML document, for a
> requirement that I have. Below is the XML fragment:
>
> <SUBMISSIONS>
> <SUBMISSION YEAR="2004">
> <MONTH NAME="JAN">10</MONTH>
> <MONTH NAME="FEB">02</MONTH>
> .
> .
> <MONTH NAME="DEC">78</MONTH>
> </SUBMISSION>
> <SUBMISSION YEAR="2005">
> <MONTH NAME="JAN">03</MONTH>
> <MONTH NAME="FEB">50</MONTH>
> .
> .
> <MONTH NAME="DEC">27</MONTH>
> </SUBMISSION>
> <SUBMISSION YEAR="2006">
> <MONTH NAME="JAN">34</MONTH>
> <MONTH NAME="FEB">65</MONTH>
> .
> .
> <MONTH NAME="DEC">22</MONTH>
> </SUBMISSION>
> <SUBMISSIONS>
>
> If a user selects a time-period from 01-MAR-2005 to 31-DEC-2006, I have to
> display month-wise counts for each of those months. i.e., I have to add March
> of 2005 and March of 2006, April of 2005 and April of 2006 and so on and so
> forth. and display the grand totals for individual months during that time
> period. As part of this requirement, I wrote the following XPath query to get
> the nodes for "NOV" from any of the years > 2005.
>
> "/SUBMISSIONS/SUBMISSION[@YEAR >= 2005]/MONTH[@NAME='NOV']"
>
> But what I really need is the time period from 2005 to 2006; and when I try
> the below query to get the nodes between this time period, I get "invalid
> token" error message:
>
> "/SUBMISSIONS/SUBMISSION[@YEAR >= 2005 AND @YEAR <= 2006]/MONTH[@NAME='NOV']"
>
> Is not this a valid Xpath query? Cannot I specify lower bound and upper
> bound simultaneously in an Xpath query? If I give only one predicate it works
> fine...
>
> Help!!!!
>
>

 
Reply With Quote
 
 
 
 
=?Utf-8?B?RGlmZmlkZW50?=
Guest
Posts: n/a
 
      03-05-2007

Thanks Bruce...that did the trick!

I changed "AND" to "and" and it worked like a charm.

"bruce barker" wrote:

> xquery is case sensitive, use "and"
>
> -- bruce (sqlwork.com)
>
> Diffident wrote:
> > Hello All,
> >
> > I am trying to construct an XPath query against an XML document, for a
> > requirement that I have. Below is the XML fragment:
> >
> > <SUBMISSIONS>
> > <SUBMISSION YEAR="2004">
> > <MONTH NAME="JAN">10</MONTH>
> > <MONTH NAME="FEB">02</MONTH>
> > .
> > .
> > <MONTH NAME="DEC">78</MONTH>
> > </SUBMISSION>
> > <SUBMISSION YEAR="2005">
> > <MONTH NAME="JAN">03</MONTH>
> > <MONTH NAME="FEB">50</MONTH>
> > .
> > .
> > <MONTH NAME="DEC">27</MONTH>
> > </SUBMISSION>
> > <SUBMISSION YEAR="2006">
> > <MONTH NAME="JAN">34</MONTH>
> > <MONTH NAME="FEB">65</MONTH>
> > .
> > .
> > <MONTH NAME="DEC">22</MONTH>
> > </SUBMISSION>
> > <SUBMISSIONS>
> >
> > If a user selects a time-period from 01-MAR-2005 to 31-DEC-2006, I have to
> > display month-wise counts for each of those months. i.e., I have to add March
> > of 2005 and March of 2006, April of 2005 and April of 2006 and so on and so
> > forth. and display the grand totals for individual months during that time
> > period. As part of this requirement, I wrote the following XPath query to get
> > the nodes for "NOV" from any of the years > 2005.
> >
> > "/SUBMISSIONS/SUBMISSION[@YEAR >= 2005]/MONTH[@NAME='NOV']"
> >
> > But what I really need is the time period from 2005 to 2006; and when I try
> > the below query to get the nodes between this time period, I get "invalid
> > token" error message:
> >
> > "/SUBMISSIONS/SUBMISSION[@YEAR >= 2005 AND @YEAR <= 2006]/MONTH[@NAME='NOV']"
> >
> > Is not this a valid Xpath query? Cannot I specify lower bound and upper
> > bound simultaneously in an Xpath query? If I give only one predicate it works
> > fine...
> >
> > Help!!!!
> >
> >

>

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
"Memory leak" in javax.xml.xpath.XPath Marvin_123456 Java 4 07-29-2005 03:49 PM
xpath query query David Gordon XML 2 05-18-2005 03:33 PM
Are there any XPath parsers that generate XPath trees? goog XML 0 01-14-2004 01:47 PM
XPath that does not include other XPath Anna XML 0 07-31-2003 07:55 AM
Problem selecting a node with XPATH if attribute value contains backslashes - how to force XPATH string to be treated as literal? Alastair Cameron XML 1 07-08-2003 07:24 PM



Advertisments