Package org.jdesktop.xpath
Class XPathUtils
java.lang.Object
org.jdesktop.xpath.XPathUtils
Various utilities for working with XPath. This class uses a static XPath object for most of it's work. This XPath object is preconfigured to use the extended XPath functions of the org.jdesktop.xpath.function package.
-
Method Summary
Modifier and TypeMethodDescriptionstatic XPathExpressionCompiles the given expression, using the internal XPath instance of this class and returns the XPathExpression.static NodegetElement(String expression, Node node)Returns a Node matching the given expression.static NodegetElement(XPathExpression expression, Node node)Returns a Node matching the given expression.static SimpleNodeListgetElements(String expression, Node node)Returns aSimpleNodeListcontaining all the nodes that match the given expression when executed on the given node (as opposed to the dom as a whole).static SimpleNodeListgetElements(XPathExpression expression, Node node)Returns aSimpleNodeListcontaining all the nodes that match the given expression when executed on the given node (as opposed to the dom as a whole).static StringReturns the text content of the Node matching the given expression.static Stringstatic StringgetString(XPathExpression expression, Node node)Returns the text content of the Node matching the given expression.static StringExports this DOM as a Stringstatic StringtoXML(Document dom, Properties outputProperties)
-
Method Details
-
getElements
public static SimpleNodeList getElements(String expression, Node node) throws XPathExpressionExceptionReturns aSimpleNodeListcontaining all the nodes that match the given expression when executed on the given node (as opposed to the dom as a whole).- Parameters:
expression- an XPath expressionnode- the contextual node- Returns:
- SimpleNodeList containing the results from the expression. This will never be null, but may contain no results.
- Throws:
IllegalArgumentException- if the expression does not parseXPathExpressionException
-
getElement
Returns a Node matching the given expression. If more than one node matches, the return value is undefined.- Parameters:
expression- an XPath expressionnode- the contextual node- Returns:
- Node. May be null.
- Throws:
IllegalArgumentException- if the expression does not parseXPathExpressionException
-
getString
Returns the text content of the Node matching the given expression. If more than one node matches, the return value is undefined.- Parameters:
expression- an XPath expressionnode- the contextual node- Returns:
- text content of the selected Node. May be null.
- Throws:
IllegalArgumentException- if the expression does not parseXPathExpressionException
-
getString
public static String getString(String expression, Node node, String namespace, String namespacePrefix) throws XPathExpressionException- Throws:
XPathExpressionException
-
getElements
public static SimpleNodeList getElements(XPathExpression expression, Node node) throws XPathExpressionExceptionReturns aSimpleNodeListcontaining all the nodes that match the given expression when executed on the given node (as opposed to the dom as a whole).- Parameters:
expression- an XPath expressionnode- the contextual node- Returns:
- SimpleNodeList containing the results from the expression. This will never be null, but may contain no results.
- Throws:
IllegalArgumentException- if the expression does not parseXPathExpressionException
-
getElement
public static Node getElement(XPathExpression expression, Node node) throws XPathExpressionExceptionReturns a Node matching the given expression. If more than one node matches, the return value is undefined.- Parameters:
expression- an XPath expressionnode- the contextual node- Returns:
- Node. May be null.
- Throws:
IllegalArgumentException- if the expression does not parseXPathExpressionException
-
getString
public static String getString(XPathExpression expression, Node node) throws XPathExpressionExceptionReturns the text content of the Node matching the given expression. If more than one node matches, the return value is undefined.- Parameters:
expression- an XPath expressionnode- the contextual node- Returns:
- text content of the selected Node. May be null.
- Throws:
IllegalArgumentException- if the expression does not parseXPathExpressionException
-
compile
Compiles the given expression, using the internal XPath instance of this class and returns the XPathExpression.- Parameters:
expression- The XPath expression to compile- Returns:
- the compiled XPathExpression
- Throws:
XPathExpressionException- for a malformed XPath expression
-
toXML
Exports this DOM as a String -
toXML
-