Help with XPath query

Discussion in 'ASP .Net' started by =?Utf-8?B?RGlmZmlkZW50?=, Mar 5, 2007.

  1. 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!!!!
    =?Utf-8?B?RGlmZmlkZW50?=, Mar 5, 2007
    #1
    1. Advertising

  2. =?Utf-8?B?RGlmZmlkZW50?=

    bruce barker Guest

    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!!!!
    >
    >
    bruce barker, Mar 5, 2007
    #2
    1. Advertising

  3. 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!!!!
    > >
    > >

    >
    =?Utf-8?B?RGlmZmlkZW50?=, Mar 5, 2007
    #3
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Marvin_123456

    "Memory leak" in javax.xml.xpath.XPath

    Marvin_123456, Jul 29, 2005, in forum: Java
    Replies:
    4
    Views:
    1,950
    jan V
    Jul 29, 2005
  2. Alastair Cameron
    Replies:
    1
    Views:
    7,364
    SQL Server Development Team [MSFT]
    Jul 8, 2003
  3. Anna
    Replies:
    0
    Views:
    504
  4. goog
    Replies:
    0
    Views:
    490
  5. David Gordon

    xpath query query

    David Gordon, May 18, 2005, in forum: XML
    Replies:
    2
    Views:
    774
    David Gordon
    May 18, 2005
Loading...

Share This Page