1

I have an xml file containing a lists of nodes with a "date" attribute, storing a date:

<root>
    <entry date="2011-12-04" />
    <entry date="2011-11-29" />
</root>

Is it possible using a xPath query to retrive all the nodes that have the month of the "date" attribute set to november?
I read on the web (for example here) that this kind of functions exists in the xPath language, but I am not able to figure how to use them.
I should using this in a java application.

2 Answers 2

3

The following XPath works for me:

//entry[month-from-date(@date)=11]

(Replace entry with * to select all the nodes with a November date attribute, regardless of the node name.)

Sign up to request clarification or add additional context in comments.

1 Comment

It may be important to add that this function is only available with XPath 2.0.
2

I haven't used the date functions, but you could use substring to extract the month and test that value, for example:

'//entry[substring(@date,6,2)="11"]'

returns just

<entry date="2011-11-29" />

1 Comment

I went the substring way,because I cannot use XPath 2 functions. Thanks.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.