See: Description
| Class | Description |
|---|---|
| XPathAPI |
The container for the various static methods exposed by the XPathAPI.
|
XPathAPI offers simple methods to select nodes on XML document trees using XPath expressions.
The XPathAPI way to select all the nodes that match the XPath
//friend[@status='best'] is:
NodeList bestFriends = XPathAPI.selectNodeList(doc, "//friend[@status='best']");
That single line is equivalent to this longer and more complex piece of code:
XPathFactory xpathFactory = XPathFactory.newInstance();
XPath xpath = xpathFactory.newXPath();
XPathExpression xpathExpr = xpath.compile("//friend[@status='best']");
NodeList bestFriends = (NodeList) xpathExpr.evaluate(contextNode, XPathConstants.NODESET);
XPathAPI is easier to use but is slower than ad-hoc optimized code, especially when multiple XPath expressions are to be evaluated on the same big XML document. You should use XPathAPI in non-time-critical code paths or for fast prototyping.
Copyright © 2011-2013. All Rights Reserved.