commons-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Desai, Jasmina" <>
Subject Using JXPATH for dates
Date Mon, 14 Jan 2008 20:48:20 GMT
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



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

                        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( at
n( at



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

Will the xs:date accept the date in dd-MM-yyyy format?





Programmer Analyst, Sr

Direct: (858) 651-1132

Ext:     11132


  • Unnamed multipart/alternative (inline, None, 0 bytes)
View raw message