Java Reference
In-Depth Information
</contact>
<contact>
<name>Jane Doe</name>
<birth>1965-07-12</birth>
<city>New York</city>
</contact>
<contact>
<name>Sandra Smith</name>
<birth>1976-11-22</birth>
<city>Denver</city>
<city>Miami</city>
</contact>
<contact>
<name>Bob Jones</name>
<birth>1958-03-14</birth>
<city>Chicago</city>
</contact>
</contacts>
Now suppose that you want to select contacts based on birth information. For ex-
ample,youonlywanttoselectcontactswhosedateofbirthisgreaterthan1960-01-01.
BecauseXPathdoesnotprovidethisfunctionforyou,youdecidetodeclarea date()
extension function. Your first step is to declare a Date class that implements the
XPathFunction interface—see Listing 10-25 .
Listing 10-25. An extension function for returning a date as a milliseconds value
import java.text.ParsePosition;
import java.text.SimpleDateFormat;
import java.util.List;
import javax.xml.xpath.XPathFunction;
import javax.xml.xpath.XPathFunctionException;
import org.w3c.dom.Node;
import org.w3c.dom.NodeList;
Search WWH ::




Custom Search