I'm trying to filter elements based on an attribute that is a date in the format yyyy-MM-dd
.
My XML looks like this:
<?xml version="1.0" encoding="utf-8"?>
<root>
<article title="wired" pub-date="2010-11-22" />
<article title="Plus 24" pub-date="2010-11-22" />
<article title="Finance" pub-date="2010-10-25" />
</root>
My xpath attempt:
'//article[xs:date(./@pub-date) > xs:date("2010-11-15")]'
Using xpath 2.0 - would avoid adding a schema unless absolutely necessary.
From comments:
I believe I must be missing something then. Is it possible that I need to specify something else for xs:date to work? Maybe a xs: namespace definition?
./
step, only for brevity one could use (for other expression).//
instead ofdescendant::
. – Godliman//article[xs:date(@pub-date) gt xs:date("2010-11-15")]
however which is a bit shorter and more compact. – Mothball