How to Compare Date in XPath Expression

Please support our XML, XSLT and XPATH advertiser: Intel Parallel Studio Home
Reply

Join Date: Nov 2009
Posts: 3
Reputation: extkml is an unknown quantity at this point 
Solved Threads: 0
extkml extkml is offline Offline
Newbie Poster

How to Compare Date in XPath Expression

 
0
  #1
20 Days Ago
I have orders.xml like the following

XML, XSLT and XPATH Syntax (Toggle Plain Text)
  1. <?xml version="1.0" encoding="UTF-8" standalone="no"?>
  2. <orders>
  3. <order orderDate="1/1/2009" orderNo="1">
  4. <customer id="nnghiem" name="nguyen nghiem"/>
  5. <item id="item-1" price="25000" quantity="0"/>
  6. <item id="item-2" price="22000" quantity="3"/>
  7. </order>
  8. <order orderDate="2/2/2009" orderNo="2">
  9. <customer id="lp" name="lampard"/>
  10. <item id="item-1" price="25000" quantity="2"/>
  11. <item id="item-2" price="22000" quantity="8"/>
  12. </order>
  13. <order orderDate="3/3/2007" orderNo="3">
  14. <customer id="nnghiem" name="nguyen nghiem"/>
  15. <item id="item-1" price="25000" quantity="7"/>
  16. <item id="item-2" price="22000" quantity="6"/>
  17. </order>
  18. </orders>

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

XML, XSLT and XPATH Syntax (Toggle Plain Text)
  1. String exp = "/orders/order[substring(@orderDate,string-length(@orderDate)-3)='2009']";
  2. //... some code lines

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

XML, XSLT and XPATH Syntax (Toggle Plain Text)
  1. 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!
Reply With Quote Quick reply to this message  
Join Date: Oct 2008
Posts: 2,563
Reputation: adatapost has much to be proud of adatapost has much to be proud of adatapost has much to be proud of adatapost has much to be proud of adatapost has much to be proud of adatapost has much to be proud of adatapost has much to be proud of adatapost has much to be proud of adatapost has much to be proud of adatapost has much to be proud of 
Solved Threads: 454
Moderator
adatapost's Avatar
adatapost adatapost is online now Online
Posting Maven
 
0
  #2
19 Days Ago
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.
Failure is not fatal, but failure to change might be. - John Wooden
Reply With Quote Quick reply to this message  
Join Date: Nov 2009
Posts: 3
Reputation: extkml is an unknown quantity at this point 
Solved Threads: 0
extkml extkml is offline Offline
Newbie Poster
 
0
  #3
19 Days Ago
thanks for your reply
Reply With Quote Quick reply to this message  
Reply

Message:



Similar Threads
Other Threads in the XML, XSLT and XPATH Forum
Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC