Class XpathUtils
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic BooleanEvaluates the specified XPath expression and returns the result as a Boolean.static BooleanSame asasBoolean(String, Node)but allows an xpath to be passed in explicitly for reuse.static ByteEvaluates the specified XPath expression and returns the result as a Byte.static ByteSame asasByte(String, Node)but allows an xpath to be passed in explicitly for reuse.static ByteBufferasByteBuffer(String expression, Node node) Evaluates the specified xpath expression, base64 decodes the data and returns the result as a ByteBuffer.static ByteBufferasByteBuffer(String expression, Node node, XPath xpath) Same asasByteBuffer(String, Node)but allows an xpath to be passed in explicitly for reuse.static DateEvaluates the specified XPath expression and returns the result as a Date.static DateSame asasDate(String, Node)but allows an xpath to be passed in explicitly for reuse.static DoubleEvaluates the specified XPath expression and returns the results as a Double.static DoubleSame asasDouble(String, Node)but allows an xpath to be passed in explicitly for reuse.static FloatEvaluates the specified XPath expression and returns the result as a Float.static FloatSame asasFloat(String, Node)but allows an xpath to be passed in explicitly for reuse.static IntegerEvaluates the specified XPath expression and returns the result as an Integer.static IntegerSame asasInteger(String, Node)but allows an xpath to be passed in explicitly for reuse.static LongEvaluates the specified XPath expression and returns the result as a Long.static LongSame asasLong(String, Node)but allows an xpath to be passed in explicitly for reuse.static NodeEvaluates the specified XPath expression and returns the result as a Node.static NodeSame asasNode(String, Node)but allows an xpath to be passed in explicitly for reuse.static StringEvaluates the specified XPath expression and returns the result as a string.static StringSame asasString(String, Node)but allows an xpath to be passed in explicitly for reuse.static DocumentThis method closes the given input stream upon completion.static DocumentdocumentFrom(String xml) static DocumentdocumentFrom(URL url) static booleanReturns true if the specified node is null or has no children.static intnodeLength(NodeList list) Returns the length of the specified node list.static XPathxpath()Returns a new instance of XPath, which is not thread safe and not reentrant.
-
Constructor Details
-
XpathUtils
public XpathUtils()
-
-
Method Details
-
xpath
Returns a new instance of XPath, which is not thread safe and not reentrant. -
documentFrom
public static Document documentFrom(InputStream is) throws SAXException, IOException, ParserConfigurationException This method closes the given input stream upon completion. -
documentFrom
public static Document documentFrom(String xml) throws SAXException, IOException, ParserConfigurationException -
documentFrom
public static Document documentFrom(URL url) throws SAXException, IOException, ParserConfigurationException -
asDouble
Evaluates the specified XPath expression and returns the results as a Double.This method can be expensive as a new xpath is instantiated per invocation. Consider passing in the xpath explicitly via {
asDouble(String, Node, XPath)instead. NoteXPathis not thread-safe and not reentrant.- Parameters:
expression- The XPath expression to evaluate.node- The node to run the expression on.- Returns:
- The Double result.
- Throws:
XPathExpressionException- If there was a problem processing the specified XPath expression.
-
asDouble
public static Double asDouble(String expression, Node node, XPath xpath) throws XPathExpressionException Same asasDouble(String, Node)but allows an xpath to be passed in explicitly for reuse.- Throws:
XPathExpressionException
-
asString
Evaluates the specified XPath expression and returns the result as a string.This method can be expensive as a new xpath is instantiated per invocation. Consider passing in the xpath explicitly via {
asDouble(String, Node, XPath)instead. NoteXPathis not thread-safe and not reentrant.- Parameters:
expression- The XPath expression to evaluate.node- The node to run the expression on.- Returns:
- The string result.
- Throws:
XPathExpressionException- If there was a problem processing the specified XPath expression.
-
asString
public static String asString(String expression, Node node, XPath xpath) throws XPathExpressionException Same asasString(String, Node)but allows an xpath to be passed in explicitly for reuse.- Throws:
XPathExpressionException
-
asInteger
Evaluates the specified XPath expression and returns the result as an Integer.This method can be expensive as a new xpath is instantiated per invocation. Consider passing in the xpath explicitly via {
asDouble(String, Node, XPath)instead. NoteXPathis not thread-safe and not reentrant.- Parameters:
expression- The XPath expression to evaluate.node- The node to run the expression on.- Returns:
- The Integer result.
- Throws:
XPathExpressionException- If there was a problem processing the specified XPath expression.
-
asInteger
public static Integer asInteger(String expression, Node node, XPath xpath) throws XPathExpressionException Same asasInteger(String, Node)but allows an xpath to be passed in explicitly for reuse.- Throws:
XPathExpressionException
-
asBoolean
Evaluates the specified XPath expression and returns the result as a Boolean.This method can be expensive as a new xpath is instantiated per invocation. Consider passing in the xpath explicitly via {
asDouble(String, Node, XPath)instead. NoteXPathis not thread-safe and not reentrant.- Parameters:
expression- The XPath expression to evaluate.node- The node to run the expression on.- Returns:
- The Boolean result.
- Throws:
XPathExpressionException- If there was a problem processing the specified XPath expression.
-
asBoolean
public static Boolean asBoolean(String expression, Node node, XPath xpath) throws XPathExpressionException Same asasBoolean(String, Node)but allows an xpath to be passed in explicitly for reuse.- Throws:
XPathExpressionException
-
asFloat
Evaluates the specified XPath expression and returns the result as a Float.This method can be expensive as a new xpath is instantiated per invocation. Consider passing in the xpath explicitly via {
asDouble(String, Node, XPath)instead. NoteXPathis not thread-safe and not reentrant.- Parameters:
expression- The XPath expression to evaluate.node- The node to run the expression on.- Returns:
- The Float result.
- Throws:
XPathExpressionException- If there was a problem processing the specified XPath expression.
-
asFloat
public static Float asFloat(String expression, Node node, XPath xpath) throws XPathExpressionException Same asasFloat(String, Node)but allows an xpath to be passed in explicitly for reuse.- Throws:
XPathExpressionException
-
asLong
Evaluates the specified XPath expression and returns the result as a Long.This method can be expensive as a new xpath is instantiated per invocation. Consider passing in the xpath explicitly via {
asDouble(String, Node, XPath)instead. NoteXPathis not thread-safe and not reentrant.- Parameters:
expression- The XPath expression to evaluate.node- The node to run the expression on.- Returns:
- The Long result.
- Throws:
XPathExpressionException- If there was a problem processing the specified XPath expression.
-
asLong
public static Long asLong(String expression, Node node, XPath xpath) throws XPathExpressionException Same asasLong(String, Node)but allows an xpath to be passed in explicitly for reuse.- Throws:
XPathExpressionException
-
asByte
Evaluates the specified XPath expression and returns the result as a Byte.This method can be expensive as a new xpath is instantiated per invocation. Consider passing in the xpath explicitly via {
asDouble(String, Node, XPath)instead. NoteXPathis not thread-safe and not reentrant.- Parameters:
expression- The XPath expression to evaluate.node- The node to run the expression on.- Returns:
- The Byte result.
- Throws:
XPathExpressionException- If there was a problem processing the specified XPath expression.
-
asByte
public static Byte asByte(String expression, Node node, XPath xpath) throws XPathExpressionException Same asasByte(String, Node)but allows an xpath to be passed in explicitly for reuse.- Throws:
XPathExpressionException
-
asDate
Evaluates the specified XPath expression and returns the result as a Date. Assumes that the node's text is formatted as an ISO 8601 date, as specified by xs:dateTime.This method can be expensive as a new xpath is instantiated per invocation. Consider passing in the xpath explicitly via {
asDouble(String, Node, XPath)instead. NoteXPathis not thread-safe and not reentrant.- Parameters:
expression- The XPath expression to evaluate.node- The node to run the expression on.- Returns:
- The Date result.
- Throws:
XPathExpressionException- If there was a problem processing the specified XPath expression.
-
asDate
public static Date asDate(String expression, Node node, XPath xpath) throws XPathExpressionException Same asasDate(String, Node)but allows an xpath to be passed in explicitly for reuse.- Throws:
XPathExpressionException
-
asByteBuffer
Evaluates the specified xpath expression, base64 decodes the data and returns the result as a ByteBuffer.This method can be expensive as a new xpath is instantiated per invocation. Consider passing in the xpath explicitly via {
asDouble(String, Node, XPath)instead. NoteXPathis not thread-safe and not reentrant.- Parameters:
expression- The Xpath expression to evaluate.node- The node on which to evaluate the expression.- Returns:
- A ByteBuffer of base64 decoded data from the result of evaluating the specified Xpath expression.
- Throws:
XPathExpressionException- If there are any problems evaluating the Xpath expression.
-
asByteBuffer
public static ByteBuffer asByteBuffer(String expression, Node node, XPath xpath) throws XPathExpressionException Same asasByteBuffer(String, Node)but allows an xpath to be passed in explicitly for reuse.- Throws:
XPathExpressionException
-
isEmpty
Returns true if the specified node is null or has no children.- Parameters:
node- The node to test.- Returns:
- True if the specified node is null or has no children.
-
asNode
Evaluates the specified XPath expression and returns the result as a Node.- Parameters:
nodeName- The XPath expression to evaluate.node- The node to run the expression on.- Returns:
- The Node result.
- Throws:
XPathExpressionException- If there was a problem processing the specified XPath expression.
-
asNode
Same asasNode(String, Node)but allows an xpath to be passed in explicitly for reuse.- Throws:
XPathExpressionException
-
nodeLength
Returns the length of the specified node list.- Parameters:
list- The node list to measure.- Returns:
- The length of the specified node list.
-