|
|||||||||
| PREV PACKAGE NEXT PACKAGE | FRAMES NO FRAMES | ||||||||
See:
Description
| Class Summary | |
|---|---|
| XPathAPI | The container for the various static methods exposed by the XPathAPI. |
Select XML nodes using XPath and a single line of Java code.
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.
|
|||||||||
| PREV PACKAGE NEXT PACKAGE | FRAMES NO FRAMES | ||||||||