it.svario.xpathapi.jaxp
Class XPathAPI

java.lang.Object
  extended by it.svario.xpathapi.jaxp.XPathAPI

public class XPathAPI
extends Object

The container for the various static methods exposed by the XPathAPI.

See the XPathAPI package documentation for an overview of XPathAPI and examples of how to use these methods.

See Also:
it.svario.xpathapi.jaxp

Constructor Summary
XPathAPI()
           
 
Method Summary
static List<Node> selectListOfNodes(Node contextNode, String xpathString)
          Selects all the nodes that match the given XPath expression (returns a List<Node> list).
static List<Node> selectListOfNodes(Node contextNode, String xpathString, Map<String,String> namespaces)
          Selects all the nodes that match the given XPath expression, taking into account the namespace mappings defined in namespaces (returns a List<Node> list).
static List<Node> selectListOfNodes(Node contextNode, String xpathString, Node namespaceNode)
          Selects all the nodes that match the given XPath expression, taking into account all namespaces found in namespaceNode (returns a List<Node> list).
static org.w3c.dom.traversal.NodeIterator selectNodeIterator(Node contextNode, String xpathString)
          Returns an iterator over all the nodes that match the given XPath expression.
static org.w3c.dom.traversal.NodeIterator selectNodeIterator(Node contextNode, String xpathString, Node namespaceNode)
          Returns an iterator over all the nodes that match the given XPath expression, taking into account all namespaces found in namespaceNode.
static NodeList selectNodeList(Node contextNode, String xpathString)
          Selects all the nodes that match the given XPath expression (returns a org.w3c.dom.NodeList list).
static NodeList selectNodeList(Node contextNode, String xpathString, Map<String,String> namespaces)
          Selects all the nodes that match the given XPath expression, taking into account the namespace mappings defined in namespaces (returns a org.w3c.dom.NodeList list).
static NodeList selectNodeList(Node contextNode, String xpathString, Node namespaceNode)
          Selects all the nodes that match the given XPath expression, taking into account all namespaces found in namespaceNode (returns a org.w3c.dom.NodeList list).
static List<String> selectNodeListAsStrings(Node contextNode, String xpathString)
          Returns a list with the textual content of all the nodes that match the given XPath expression.
static List<String> selectNodeListAsStrings(Node contextNode, String xpathString, Map<String,String> namespaces)
          Returns a list with the textual content of all the nodes that match the given XPath expression, taking into account the namespace mappings defined in namespaces.
static List<String> selectNodeListAsStrings(Node contextNode, String xpathString, Node namespaceNode)
          Returns a list with the textual content of all the nodes that match the given XPath expression, taking into account all namespaces found namespaceNode.
static Node selectSingleNode(Node contextNode, String xpathString)
          Selects the first node that matches the given XPath expression.
static Node selectSingleNode(Node contextNode, String xpathString, Map<String,String> namespaces)
          Selects the first node that matches the given XPath expression, taking additional namespace from the namespaces mapping.
static Node selectSingleNode(Node contextNode, String xpathString, Node namespaceNode)
          Selects the first node that matches the given XPath expression, taking into account all namespaces found in namespaceNode.
static String selectSingleNodeAsString(Node contextNode, String xpathString)
          Returns the textual content of the first node that matches the given XPath expression.
static String selectSingleNodeAsString(Node contextNode, String xpathString, Map<String,String> namespaces)
          Returns the textual content of the first node that matches the given XPath expression, taking into account the namespace mappings defined in namespaces.
static String selectSingleNodeAsString(Node contextNode, String xpathString, Node namespaceNode)
          Returns the textual content of the first node that matches the given XPath expression, taking into account all namespaces found namespaceNode.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

XPathAPI

public XPathAPI()
Method Detail

selectSingleNode

public static Node selectSingleNode(Node contextNode,
                                    String xpathString)
                             throws XPathException
Selects the first node that matches the given XPath expression.

The only namespaces prefixes usable in the XPath expression are those available in contextNode. If other additional prefixes are required, use selectSingleNode(Node, String, Map) or selectSingleNode(Node, String, Node).

Parameters:
contextNode - the node from which the XPath expression is evaluated
xpathString - the XPath expression to evaluate
Returns:
the first matching node or null in case the XPath evaluated to an empty node set
Throws:
XPathException

selectSingleNode

public static Node selectSingleNode(Node contextNode,
                                    String xpathString,
                                    Map<String,String> namespaces)
                             throws XPathException
Selects the first node that matches the given XPath expression, taking additional namespace from the namespaces mapping.

This function behaves like selectSingleNode(Node, String), but the namespace prefixes that can be used in the XPath expression are not only those available in contextNode, but also the ones defined in the namespaces mapping.

Parameters:
contextNode - the node from which the XPath expression is evaluated
xpathString - the XPath expression to evaluate
namespaces - a mapping between namespace prefixes and URIs
Returns:
the first matching node or null in case the XPath evaluated to an empty node set
Throws:
XPathException

selectSingleNode

public static Node selectSingleNode(Node contextNode,
                                    String xpathString,
                                    Node namespaceNode)
                             throws XPathException
Selects the first node that matches the given XPath expression, taking into account all namespaces found in namespaceNode.

This function behaves like selectSingleNode(Node, String), but the namespace prefixes that can be used in the XPath expression are not those available in contextNode, but those available in namespaceNode.

Parameters:
contextNode - the node from which the XPath expression is evaluated
xpathString - the XPath expression to evaluate
namespaceNode - the node from which all the namespace declarations will be taken
Returns:
the first matching node or null in case the XPath evaluated to an empty node set
Throws:
XPathException

selectSingleNodeAsString

public static String selectSingleNodeAsString(Node contextNode,
                                              String xpathString)
                                       throws XPathException
Returns the textual content of the first node that matches the given XPath expression.

The only namespaces prefixes usable in the XPath expression are those available in contextNode. If other additional prefixes are required, use selectSingleNodeAsString(Node, String, Map) or selectSingleNodeAsString(Node, String, Node).

 Node node = selectSingleNode(contextNode, xpathString);
 return node.getTextContent();
 

Parameters:
contextNode - the node from which the XPath expression is evaluated
xpathString - the XPath expression to evaluate
Returns:
the content of the selected node or null in case the XPath evaluated to an empty node set
Throws:
XPathException
See Also:
selectSingleNode(Node, String)

selectSingleNodeAsString

public static String selectSingleNodeAsString(Node contextNode,
                                              String xpathString,
                                              Map<String,String> namespaces)
                                       throws XPathException
Returns the textual content of the first node that matches the given XPath expression, taking into account the namespace mappings defined in namespaces.

Basically, this method is equivalent to

 Node node = selectSingleNode(contextNode, xpathString, namespaces);
 return node.getTextContent();
 

Parameters:
contextNode - the node from which the XPath expression is evaluated
xpathString - the XPath expression to evaluate
namespaces - a mapping between namespace prefixes and URIs
Returns:
the content of the selected node or null in case the XPath evaluated to an empty node set
Throws:
XPathException
See Also:
selectSingleNode(Node, String, Map)

selectSingleNodeAsString

public static String selectSingleNodeAsString(Node contextNode,
                                              String xpathString,
                                              Node namespaceNode)
                                       throws XPathException
Returns the textual content of the first node that matches the given XPath expression, taking into account all namespaces found namespaceNode.

Basically, this method is equivalent to

 Node node = selectSingleNode(contextNode, xpathString, namespaceNode);
 return node.getTextContent();
 

Parameters:
contextNode - the node from which the XPath expression is evaluated
xpathString - the XPath expression to evaluate
namespaceNode - the node from which all the namespace declarations will be taken
Returns:
the content of the selected node or null in case the XPath evaluated to an empty node set
Throws:
XPathException
See Also:
selectSingleNode(Node, String, Node)

selectNodeList

public static NodeList selectNodeList(Node contextNode,
                                      String xpathString)
                               throws XPathException
Selects all the nodes that match the given XPath expression (returns a org.w3c.dom.NodeList list).

The only namespaces prefixes usable in the XPath expression are those available in contextNode. If other additional prefixes are required, use selectNodeList(Node, String, Map) or selectNodeList(Node, String, Node).

It is better to use the selectListOfNodes(Node, String) method because it returns a List<Node> instead of a legacy org.w3c.dom.NodeList.

Parameters:
contextNode - the node from which the XPath expression is evaluated
xpathString - the XPath expression to evaluate
Returns:
all the nodes that match the given XPath expression
Throws:
XPathException
See Also:
selectListOfNodes(Node, String)

selectNodeList

public static NodeList selectNodeList(Node contextNode,
                                      String xpathString,
                                      Node namespaceNode)
                               throws XPathException
Selects all the nodes that match the given XPath expression, taking into account all namespaces found in namespaceNode (returns a org.w3c.dom.NodeList list).

This function behaves like selectNodeList(Node, String), but the namespace prefixes that can be used in the XPath expression are not those available in contextNode, but those available in namespaceNode.

It is better to use the selectListOfNodes(Node, String, Node) method because it returns a List<Node> instead of a legacy org.w3c.dom.NodeList.

Parameters:
contextNode - the node from which the XPath expression is evaluated
xpathString - the XPath expression to evaluate
namespaceNode - the node from which all the namespace declarations will be taken
Returns:
all the nodes that match the given XPath expression
Throws:
XPathException
See Also:
selectListOfNodes(Node, String, Node)

selectNodeList

public static NodeList selectNodeList(Node contextNode,
                                      String xpathString,
                                      Map<String,String> namespaces)
                               throws XPathException
Selects all the nodes that match the given XPath expression, taking into account the namespace mappings defined in namespaces (returns a org.w3c.dom.NodeList list).

This function behaves like selectNodeList(Node, String), but the namespace prefixes that can be used in the XPath expression are not only those available in contextNode, but also the ones defined in the namespaces mapping.

It is better to use the selectListOfNodes(Node, String, Map) method because it returns a List<Node> instead of a legacy org.w3c.dom.NodeList.

Parameters:
contextNode - the node from which the XPath expression is evaluated
xpathString - the XPath expression to evaluate
namespaces - a mapping between namespace prefixes and URIs
Returns:
all the nodes that match the given XPath expression
Throws:
XPathException
See Also:
selectListOfNodes(Node, String, Map)

selectListOfNodes

public static List<Node> selectListOfNodes(Node contextNode,
                                           String xpathString)
                                    throws XPathException
Selects all the nodes that match the given XPath expression (returns a List<Node> list).

The only namespaces prefixes usable in the XPath expression are those available in contextNode. If other additional prefixes are required, use selectListOfNodes(Node, String, Map) or selectListOfNodes(Node, String, Node).

Parameters:
contextNode - the node from which the XPath expression is evaluated
xpathString - the XPath expression to evaluate
Returns:
all the nodes that match the given XPath expression
Throws:
XPathException

selectListOfNodes

public static List<Node> selectListOfNodes(Node contextNode,
                                           String xpathString,
                                           Node namespaceNode)
                                    throws XPathException
Selects all the nodes that match the given XPath expression, taking into account all namespaces found in namespaceNode (returns a List<Node> list).

This function behaves like selectListOfNodes(Node, String), but the namespace prefixes that can be used in the XPath expression are not those available in contextNode, but those available in namespaceNode.

Parameters:
contextNode - the node from which the XPath expression is evaluated
xpathString - the XPath expression to evaluate
namespaceNode - the node from which all the namespace declarations will be taken
Returns:
all the nodes that match the given XPath expression
Throws:
XPathException

selectListOfNodes

public static List<Node> selectListOfNodes(Node contextNode,
                                           String xpathString,
                                           Map<String,String> namespaces)
                                    throws XPathException
Selects all the nodes that match the given XPath expression, taking into account the namespace mappings defined in namespaces (returns a List<Node> list).

This function behaves like selectListOfNodes(Node, String), but the namespace prefixes that can be used in the XPath expression are not only those available in contextNode, but also the ones defined in the namespaces mapping.

Parameters:
contextNode - the node from which the XPath expression is evaluated
xpathString - the XPath expression to evaluate
namespaces - a mapping between namespace prefixes and URIs
Returns:
all the nodes that match the given XPath expression
Throws:
XPathException

selectNodeListAsStrings

public static List<String> selectNodeListAsStrings(Node contextNode,
                                                   String xpathString)
                                            throws XPathException
Returns a list with the textual content of all the nodes that match the given XPath expression.

The only namespaces prefixes usable in the XPath expression are those available in contextNode. If other additional prefixes are required, use selectNodeListAsStrings(Node, String, Map) or selectNodeListAsStrings(Node, String, Node).

Parameters:
contextNode - the node from which the XPath expression is evaluated
xpathString - the XPath expression to evaluate
Returns:
a list with the textual content of the matching nodes
Throws:
XPathException
See Also:
selectNodeList(Node, String)

selectNodeListAsStrings

public static List<String> selectNodeListAsStrings(Node contextNode,
                                                   String xpathString,
                                                   Map<String,String> namespaces)
                                            throws XPathException
Returns a list with the textual content of all the nodes that match the given XPath expression, taking into account the namespace mappings defined in namespaces.

This function behaves like selectNodeListAsStrings(Node, String), but the namespace prefixes that can be used in the XPath expression are not only those available in contextNode, but also the ones defined in the namespaces mapping.

Parameters:
contextNode - the node from which the XPath expression is evaluated
xpathString - the XPath expression to evaluate
namespaces -
Returns:
a list with the textual content of the matching nodes
Throws:
XPathException
See Also:
selectNodeList(Node, String, Map)

selectNodeListAsStrings

public static List<String> selectNodeListAsStrings(Node contextNode,
                                                   String xpathString,
                                                   Node namespaceNode)
                                            throws XPathException
Returns a list with the textual content of all the nodes that match the given XPath expression, taking into account all namespaces found namespaceNode.

This function behaves like selectNodeListAsStrings(Node, String), but the namespace prefixes that can be used in the XPath expression are not those available in contextNode, but those available in namespaceNode.

Parameters:
contextNode - the node from which the XPath expression is evaluated
xpathString - the XPath expression to evaluate
namespaceNode - the node from which all the namespace declarations will be taken
Returns:
a list with the textual content of the matching nodes
Throws:
XPathException
See Also:
selectNodeList(Node, String, Node)

selectNodeIterator

public static org.w3c.dom.traversal.NodeIterator selectNodeIterator(Node contextNode,
                                                                    String xpathString)
                                                             throws XPathException
Returns an iterator over all the nodes that match the given XPath expression.

Same as selectNodeList(Node, String) but returns a NodeIterator instead of a simple NodeList.

The only namespaces prefixes usable in the XPath expression are those available in contextNode. If other additional prefixes are required, use selectNodeIterator(Node, String, Node).

Parameters:
contextNode - the node from which the XPath expression is evaluated
xpathString - the XPath expression to evaluate
Returns:
an iterator over all the nodes that match the given XPath expression
Throws:
XPathException
See Also:
selectNodeList(Node, String)

selectNodeIterator

public static org.w3c.dom.traversal.NodeIterator selectNodeIterator(Node contextNode,
                                                                    String xpathString,
                                                                    Node namespaceNode)
                                                             throws XPathException
Returns an iterator over all the nodes that match the given XPath expression, taking into account all namespaces found in namespaceNode.

Same as selectNodeList(Node, String, Node) but returns a NodeIterator instead of a simple NodeList.

This function behaves like selectNodeIterator(Node, String), but the namespace prefixes that can be used in the XPath expression are not those available in contextNode, but those available in namespaceNode.

Parameters:
contextNode - the node from which the XPath expression is evaluated
xpathString - the XPath expression to evaluate
namespaceNode - the node from which all the namespace declarations will be taken
Returns:
an iterator over all the nodes that match the given XPath expression
Throws:
XPathException
See Also:
selectNodeList(Node, String, Node)


Copyright © 2011. All Rights Reserved.