Help getting started with XPath
Hello,
I am just trying to get going with XML and XPath. I have downloaded java sdk version 1.5 that comes with the XPath implementation. However, there are no examples provided...that I can find.
Could someone provide a quick example of how to implement Sun's version of XPath, or point me to a tutorial that does this, or tell me how to implement one of the other XPath implementations.
Thanks for any and all assistance,
Mike
[460 byte] By [
MikeEller] at [2007-9-30 21:59:57]

A good XPath tutorial is here: http://www.w3schools.com/xpath/
I use the Aapche DOM API XPath implementation which is quite straight forward:. Here's an example:
/**
* Get value of the node specified by an XPath.
*
* @param document Document to get node value of.
* @param xPath XPath to select single node value (e.g. "/root/data/value[1]/text()")
* @return Result of <i>xPath</i> (the node's value) or null if failed.
* @throws XPathException if XPath result object is not of type XPathResult.
* @see <a href="http://www.w3schools.com/xpath/default.asp">XPath Tutorial</a>
*/
static public String getXPathValue(Document document, String xPath) throws XPathException {
String result = null;
if (document != null && xPath != null) {
XPathEvaluator evaluator = new XPathEvaluatorImpl(document);
Object o = evaluator.evaluate(xPath, document, evaluator.createNSResolver(document), XPathResult.FIRST_ORDERED_NODE_TYPE, null);
if (o != null) {
if (o instanceof XPathResult) {
XPathResult xpResult = (XPathResult) o;
Node node = xpResult.getSingleNodeValue();
if (node != null) {
result = node.getNodeValue();
}
} else {
throw new XPathException(XPathException.TYPE_ERR, "XPath '"+xPath+"' didn't return an object of type XPathResult!");
}
}//else: no result for XPath
}//else: input values not available
return result;
}//getXPathValue()
Hi ,
I am new to xpath and Jdom can any one help me sort out my reequirement.
here I am attaching small portion of my xml file:
Cases
Golf SMS campaign
Tunes and Pix SMS campaign
Top-up SMS being sent to customers
ThreePay television ads July 04
I need to get the cases based on the creation time.
Thanks
Babu H