I have orders.xml like the following

<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<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 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 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"/>

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!

Recommended Answers

All 2 Replies

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.

thanks for your reply

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, learning, and sharing knowledge.