org.schmant.support.xml.xpath
Class XPathSupport

java.lang.Object
  extended by org.schmant.support.xml.xpath.XPathSupport

public final class XPathSupport
extends Object

Utility class with static methods for XPath.

Since:
0.7.1
Author:
Karl Gustafsson

Method Summary
static Node getNode(XPath xp, Node n, String expr)
          Get the document Node matching the supplied XPath expression.
static NodeList getNodeList(XPath xp, Node n, String expr)
          Get the list of Node:s matching the supplied XPath expression.
static Object getObject(XPath xp, Node n, String expr, QName type)
          Get the object that is returned when evaluating the supplied XPath expression.
static String getString(XPath xp, Node n, String expr)
          Get the text returned when evaluating the supplied XPath expression.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

getObject

public static Object getObject(XPath xp,
                               Node n,
                               String expr,
                               QName type)
                        throws SchmantException
Get the object that is returned when evaluating the supplied XPath expression.

Parameters:
xp - The XPath object.
n - The Node to evaluate the expression from.
expr - The XPath expression.
type - The type of object to return.
Returns:
The result from evaluating the XPath expression.
Throws:
SchmantException - If the XPath expression did not return any value, or on other errors.

getNode

public static Node getNode(XPath xp,
                           Node n,
                           String expr)
                    throws SchmantException
Get the document Node matching the supplied XPath expression.

Parameters:
xp - The XPath object.
n - The Node to evaluate the expression from.
expr - The XPath expression.
Returns:
The Node matching the expression.
Throws:
SchmantException - If no Node matched the expression, or on other evaluation errors.

getNodeList

public static NodeList getNodeList(XPath xp,
                                   Node n,
                                   String expr)
                            throws SchmantException
Get the list of Node:s matching the supplied XPath expression.

Parameters:
xp - The XPath object.
n - The Node to evaluate the expression from.
expr - The XPath expression.
Returns:
The list of Node:s matching the expression. If no nodes match the expression, an empty list is returned.
Throws:
SchmantException - On evaluation errors.

getString

public static String getString(XPath xp,
                               Node n,
                               String expr)
                        throws SchmantException
Get the text returned when evaluating the supplied XPath expression.

Parameters:
xp - The XPath object.
n - The Node to evaluate the expression from.
expr - The XPath expression.
Returns:
The text returned when evaluating the expression, or an empty string if the expression did not return any text.
Throws:
SchmantException - On evaluation errors.