0

I have orders.xml like the following

<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<orders>
<order orderDate="1/1/2009" orderNo="1">
<customer id="nnghiem" name="nguyen nghiem"/>
<item id="item-1" price="25000" quantity="0"/>
<item id="item-2" price="22000" quantity="3"/>
</order>
<order orderDate="2/2/2009" orderNo="2">
<customer id="lp" name="lampard"/>
<item id="item-1" price="25000" quantity="2"/>
<item id="item-2" price="22000" quantity="8"/>
</order>
<order orderDate="3/3/2007" orderNo="3">
<customer id="nnghiem" name="nguyen nghiem"/>
<item id="item-1" price="25000" quantity="7"/>
<item id="item-2" price="22000" quantity="6"/>
</order>
</orders>

I want to retrieve every order in '2009
I solved this problem by the following way:

String exp = "/orders/order[substring(@orderDate,string-length(@orderDate)-3)='2009']";
//... some code lines

I wonder is there any way to compare date in this situation like this:

String exp = "/orders/order[@orderDate<'31/12/2009' and @orderDate>'1/1/2009']";

// get all orders between 1/1/2009 and 31/12/2009 (in year 2009)

but this exp will not return the expected result

How to solve this problem?

Thanks for your attention!

2
Contributors
2
Replies
3
Views
8 Years
Discussion Span
Last Post by extkml
0

XPath 1.0 only supports number comparison. XPath 2.0 understands the date type. With XPath 1.0 you need to do a string comparison. There is no other way.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.