You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@commons.apache.org by Matt Benson <gu...@yahoo.com> on 2008/01/14 23:42:43 UTC

Re: [jxpath] Using JXPATH for dates

Hi,
  To be quite honest I'm not sure where the "xs:"
portions of your example, and question, are coming
from.  Maybe if you provide a little more basic detail
to describe how you got to the point you're at with
JXPath, the list could be of more help.

-Matt

--- "Desai, Jasmina" <jd...@qualcomm.com> wrote:

> I am using JXPATH to build a java expression which
> can be used to get
> records from a table if its columns fall between a
> specific date range.
> 
> Basically I have a client application which asks the
> end user to enter a
> date range.
> 
> The application needs to get the results which fall
> between the
> specified date range.
> 
>  
> 
> I have something like this for the lower value of
> the date range:
> 
>  
> 
> if (criterion.getValue() instanceof Date) {
> 
>                   SimpleDateFormat dateFormat = new
> SimpleDateFormat("yyyy-MM-dd"); // TODO 01-DEC-2007
> i.e. dd-MM-yyyy
> 
>                   valueAsJXPath = "xs:date:('" +
> dateFormat.format(((Date) criterion.getValue())) +
> ")'";  //DOES NOT
> WORK
> 
>             }
> 
>  
> 
> Here the "Date" is of type java.util.Date.
> 
>  
> 
> Then I have the following for the upper value:
> 
>  
> 
> if (criterion.getUpperValue() instanceof Date) {
> 
>                         SimpleDateFormat dateFormat
> = new
> SimpleDateFormat("yyyy-MM-dd");
> 
>                         upperValueAsJXPath =
> "xs:date:('" +
> dateFormat.format(((Date)
> criterion.getUpperValue())) + ")'"; 
> 
>                   }
> 
>  
> 
>  
> 
> The xpath sentence that gets created is something
> like 
> 
>  
> 
> marketData/enteredMarketDate >=
> xs:date:('2008-01-01)' and
> marketData/enteredMarketDate <=
> xs:date:('2008-01-15)'
> 
>  
> 
> But I get an error which says:
> 
>  
> 
> An Exception has occured:
> org.apache.commons.jxpath.JXPathException:
> Invalid XPath:
> '/wirelessDevices[marketData/enteredMarketDate >=
> xs:date:(\'2008-01-01)\' and
> marketData/enteredMarketDate <=
> xs:date:(\'2008-01-15)\' ]'. Syntax error after:
> '/wirelessDevices[marketData/enteredMarketDate >=
> xs:d' at
>
org.apache.commons.jxpath.ri.Parser.parseExpression(Parser.java:60)
> at
>
org.apache.commons.jxpath.ri.JXPathContextReferenceImpl.compileExpressio
> n(JXPathContextReferenceImpl.java:218) at
>
org.apache.commons.jxpath.ri.JXPathContextReferenceImpl.iterate(JXPathCo
> ntextReferenceImpl.java:384)
> 
>  
> 
>  
> 
> I am a first time user of JXPATH. Kindly help me
> with this error.
> 
>  
> 
> Also, I need to use the date as 01-DEC-2007 i.e.
> dd-MM-yyyy instead of
> yyyy-MM-dd.
> 
> Will the xs:date accept the date in dd-MM-yyyy
> format?
> 
>  
> 
> Thanks
> 
> Regards,
> Jasmina
> 
>  
> 
> Programmer Analyst, Sr
> 
> Direct: (858) 651-1132
> 
> Ext:     11132
> 
>  
> 
> 



      ____________________________________________________________________________________
Be a better friend, newshound, and 
know-it-all with Yahoo! Mobile.  Try it now.  http://mobile.yahoo.com/;_ylt=Ahu06i62sR8HDtDypao8Wcj9tAcJ 


---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@commons.apache.org
For additional commands, e-mail: user-help@commons.apache.org


RE: [jxpath] Using JXPATH for dates

Posted by "Desai, Jasmina" <jd...@qualcomm.com>.
HI Matt,

Thanks for the reply.

Basically my code generates a xpath sentence as follows (forget about
how it generates)

/wirelessDevices[marketData/enteredMarketDate >= xs:date:("2008-01-01")
and marketData/enteredMarketDate <= xs:date:("2008-01-14") ]

Here "wirelessDevices" is the main object which has an instance of
"marketData" object which in turn has a property "Date
enteredMarketDate".

Basically this date comes form the client side where the user selects a
date range from the calendar (just like any other web application).

So what I do is, get these dates and generate an xpath sentence and
execute it to get the results back from the database.

In all other cases like String, Boolean, Numbers etc, a similar kind of
xpath sentence works perfectly fine.

For e.g.: The sentence below works and gets me the appropriate results
back:

/wirelessDevices[marketData/operators/address/countryType/regionType/id=
'10']

Here the id (10) is a number and hence the sentence gets executed
easily. But when I try to use a date it throws an Invalid XPATH error.

I hope this explains you my problem. 

Thanks
Regards,
Jasmina
 
Programmer Analyst, Sr
Direct: (858) 651-1132
Ext:     11132

-----Original Message-----
From: Matt Benson [mailto:gudnabrsam@yahoo.com] 
Sent: Monday, January 14, 2008 2:43 PM
To: Jakarta Commons Users List
Subject: Re: [jxpath] Using JXPATH for dates

Hi,
  To be quite honest I'm not sure where the "xs:"
portions of your example, and question, are coming
from.  Maybe if you provide a little more basic detail
to describe how you got to the point you're at with
JXPath, the list could be of more help.

-Matt

--- "Desai, Jasmina" <jd...@qualcomm.com> wrote:

> I am using JXPATH to build a java expression which
> can be used to get
> records from a table if its columns fall between a
> specific date range.
> 
> Basically I have a client application which asks the
> end user to enter a
> date range.
> 
> The application needs to get the results which fall
> between the
> specified date range.
> 
>  
> 
> I have something like this for the lower value of
> the date range:
> 
>  
> 
> if (criterion.getValue() instanceof Date) {
> 
>                   SimpleDateFormat dateFormat = new
> SimpleDateFormat("yyyy-MM-dd"); // TODO 01-DEC-2007
> i.e. dd-MM-yyyy
> 
>                   valueAsJXPath = "xs:date:('" +
> dateFormat.format(((Date) criterion.getValue())) +
> ")'";  //DOES NOT
> WORK
> 
>             }
> 
>  
> 
> Here the "Date" is of type java.util.Date.
> 
>  
> 
> Then I have the following for the upper value:
> 
>  
> 
> if (criterion.getUpperValue() instanceof Date) {
> 
>                         SimpleDateFormat dateFormat
> = new
> SimpleDateFormat("yyyy-MM-dd");
> 
>                         upperValueAsJXPath =
> "xs:date:('" +
> dateFormat.format(((Date)
> criterion.getUpperValue())) + ")'"; 
> 
>                   }
> 
>  
> 
>  
> 
> The xpath sentence that gets created is something
> like 
> 
>  
> 
> marketData/enteredMarketDate >=
> xs:date:('2008-01-01)' and
> marketData/enteredMarketDate <=
> xs:date:('2008-01-15)'
> 
>  
> 
> But I get an error which says:
> 
>  
> 
> An Exception has occured:
> org.apache.commons.jxpath.JXPathException:
> Invalid XPath:
> '/wirelessDevices[marketData/enteredMarketDate >=
> xs:date:(\'2008-01-01)\' and
> marketData/enteredMarketDate <=
> xs:date:(\'2008-01-15)\' ]'. Syntax error after:
> '/wirelessDevices[marketData/enteredMarketDate >=
> xs:d' at
>
org.apache.commons.jxpath.ri.Parser.parseExpression(Parser.java:60)
> at
>
org.apache.commons.jxpath.ri.JXPathContextReferenceImpl.compileExpressio
> n(JXPathContextReferenceImpl.java:218) at
>
org.apache.commons.jxpath.ri.JXPathContextReferenceImpl.iterate(JXPathCo
> ntextReferenceImpl.java:384)
> 
>  
> 
>  
> 
> I am a first time user of JXPATH. Kindly help me
> with this error.
> 
>  
> 
> Also, I need to use the date as 01-DEC-2007 i.e.
> dd-MM-yyyy instead of
> yyyy-MM-dd.
> 
> Will the xs:date accept the date in dd-MM-yyyy
> format?
> 
>  
> 
> Thanks
> 
> Regards,
> Jasmina
> 
>  
> 
> Programmer Analyst, Sr
> 
> Direct: (858) 651-1132
> 
> Ext:     11132
> 
>  
> 
> 



 
________________________________________________________________________
____________
Be a better friend, newshound, and 
know-it-all with Yahoo! Mobile.  Try it now.
http://mobile.yahoo.com/;_ylt=Ahu06i62sR8HDtDypao8Wcj9tAcJ 


---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@commons.apache.org
For additional commands, e-mail: user-help@commons.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@commons.apache.org
For additional commands, e-mail: user-help@commons.apache.org