com.amazonaws.util
Class XpathUtils

java.lang.Object
  extended by com.amazonaws.util.XpathUtils

public class XpathUtils
extends Object

Utility methods for extracting data from XML documents using Xpath expressions.


Constructor Summary
XpathUtils()
           
 
Method Summary
static Boolean asBoolean(String expression, Node node)
          Evaluates the specified XPath expression and returns the result as a Boolean.
static Byte asByte(String expression, Node node)
          Evaluates the specified XPath expression and returns the result as a Byte.
static ByteBuffer asByteBuffer(String expression, Node node)
          Evaluates the specified xpath expression, base64 decodes the data and returns the result as a ByteBuffer.
static Date asDate(String expression, Node node)
          Evaluates the specified XPath expression and returns the result as a Date.
static Double asDouble(String expression, Node node)
          Evaluates the specified XPath expression and returns the results as a Double.
static Float asFloat(String expression, Node node)
          Evaluates the specified XPath expression and returns the result as a Float.
static Integer asInteger(String expression, Node node)
          Evaluates the specified XPath expression and returns the result as an Integer.
static Long asLong(String expression, Node node)
          Evaluates the specified XPath expression and returns the result as a Long.
static Node asNode(String nodeName, Node node)
          Evaluates the specified XPath expression and returns the result as a Node.
static String asString(String expression, Node node)
          Evaluates the specified XPath expression and returns the result as a string.
static Document documentFrom(InputStream is)
           
static Document documentFrom(String xml)
           
static Document documentFrom(URL url)
           
static boolean isEmpty(Node node)
          Returns true if the specified node is null or has no children.
static int nodeLength(NodeList list)
          Returns the length of the specified node list.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

XpathUtils

public XpathUtils()
Method Detail

documentFrom

public static Document documentFrom(InputStream is)
                             throws SAXException,
                                    IOException,
                                    ParserConfigurationException
Throws:
SAXException
IOException
ParserConfigurationException

documentFrom

public static Document documentFrom(String xml)
                             throws SAXException,
                                    IOException,
                                    ParserConfigurationException
Throws:
SAXException
IOException
ParserConfigurationException

documentFrom

public static Document documentFrom(URL url)
                             throws SAXException,
                                    IOException,
                                    ParserConfigurationException
Throws:
SAXException
IOException
ParserConfigurationException

asDouble

public static Double asDouble(String expression,
                              Node node)
                       throws XPathExpressionException
Evaluates the specified XPath expression and returns the results as a Double.

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.

asString

public static String asString(String expression,
                              Node node)
                       throws XPathExpressionException
Evaluates the specified XPath expression and returns the result as a string.

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.

asInteger

public static Integer asInteger(String expression,
                                Node node)
                         throws XPathExpressionException
Evaluates the specified XPath expression and returns the result as an Integer.

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.

asBoolean

public static Boolean asBoolean(String expression,
                                Node node)
                         throws XPathExpressionException
Evaluates the specified XPath expression and returns the result as a Boolean.

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.

asFloat

public static Float asFloat(String expression,
                            Node node)
                     throws XPathExpressionException
Evaluates the specified XPath expression and returns the result as a Float.

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.

asLong

public static Long asLong(String expression,
                          Node node)
                   throws XPathExpressionException
Evaluates the specified XPath expression and returns the result as a Long.

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.

asByte

public static Byte asByte(String expression,
                          Node node)
                   throws XPathExpressionException
Evaluates the specified XPath expression and returns the result as a Byte.

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.

asDate

public static Date asDate(String expression,
                          Node node)
                   throws XPathExpressionException
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.

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.

asByteBuffer

public static ByteBuffer asByteBuffer(String expression,
                                      Node node)
                               throws XPathExpressionException
Evaluates the specified xpath expression, base64 decodes the data and returns the result as a ByteBuffer.

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.

isEmpty

public static boolean isEmpty(Node node)
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

public static Node asNode(String nodeName,
                          Node node)
                   throws XPathExpressionException
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.

nodeLength

public static int nodeLength(NodeList list)
Returns the length of the specified node list.

Parameters:
list - The node list to measure.
Returns:
The length of the specified node list.


Copyright © 2016. All rights reserved.