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, Map<String,String> namespaces, String... args)
          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, String... args)
          Selects all the nodes that match the given XPath expression, taking into account all namespaces found in namespaceNode (returns a List<Node> list).
static List<Node> selectListOfNodes(Node contextNode, String xpathString, String... args)
          Selects all the nodes that match the given XPath expression (returns a List<Node> list).
static org.w3c.dom.traversal.NodeIterator selectNodeIterator(Node contextNode, String xpathString, Node namespaceNode, String... args)
          Returns an iterator over all the nodes that match the given XPath expression, taking into account all namespaces found in namespaceNode.
static org.w3c.dom.traversal.NodeIterator selectNodeIterator(Node contextNode, String xpathString, String... args)
          Returns an iterator over all the nodes that match the given XPath expression.
static NodeList selectNodeList(Node contextNode, String xpathString, Map<String,String> namespaces, String... args)
          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, String... args)
          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 NodeList selectNodeList(Node contextNode, String xpathString, String... args)
          Selects all the nodes that match the given XPath expression (returns a org.w3c.dom.NodeList list).
static List<String> selectNodeListAsStrings(Node contextNode, String xpathString, Map<String,String> namespaces, String... args)
          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, String... args)
          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 List<String> selectNodeListAsStrings(Node contextNode, String xpathString, String... args)
          Returns a list with the textual content of all the nodes that match the given XPath expression.
static Node selectSingleNode(Node contextNode, String xpathString, Map<String,String> namespaces, String... args)
          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, String... args)
          Selects the first node that matches the given XPath expression, taking into account all namespaces found in namespaceNode.
static Node selectSingleNode(Node contextNode, String xpathString, String... args)
          Selects the first node that matches the given XPath expression.
static String selectSingleNodeAsString(Node contextNode, String xpathString, Map<String,String> namespaces, String... args)
          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, String... args)
          Returns the textual content of the first node that matches the given XPath expression, taking into account all namespaces found namespaceNode.
static String selectSingleNodeAsString(Node contextNode, String xpathString, String... args)
          Returns the textual content of the first node that matches the given XPath expression.
 
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,
                                    String... args)
                             throws XPathException
Selects the first node that matches the given XPath expression.

Any "{}" place-holder in the XPath expression is replaced with the content of the respective replacement string supplied in args. Please note that no escaping is performed on the replacement strings, beware of single and double quotes.

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, String...) or selectSingleNode(Node, String, Node, String...).

Parameters:
contextNode - the node from which the XPath expression is evaluated
xpathString - the XPath expression to evaluate
args - an optional array of strings used to replace the "{}" place-holders in xpathString
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,
                                    String... args)
                             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, 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
args - an optional array of strings used to replace the "{}" place-holders in xpathString
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,
                                    String... args)
                             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, 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
args - an optional array of strings used to replace the "{}" place-holders in xpathString
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,
                                              String... args)
                                       throws XPathException
Returns the textual content of the first node that matches the given XPath expression.

Any "{}" place-holder in the XPath expression is replaced with the content of the respective replacement string supplied in args. Please note that no escaping is performed on the replacement strings, beware of single and double quotes.

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, String...) or selectSingleNodeAsString(Node, String, Node, String...).

Parameters:
contextNode - the node from which the XPath expression is evaluated
xpathString - the XPath expression to evaluate
args - an optional array of strings used to replace the "{}" place-holders in xpathString
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, String...)

selectSingleNodeAsString

public static String selectSingleNodeAsString(Node contextNode,
                                              String xpathString,
                                              Map<String,String> namespaces,
                                              String... args)
                                       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
args - an optional array of strings used to replace the "{}" place-holders in xpathString
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, String...)

selectSingleNodeAsString

public static String selectSingleNodeAsString(Node contextNode,
                                              String xpathString,
                                              Node namespaceNode,
                                              String... args)
                                       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
args - an optional array of strings used to replace the "{}" place-holders in xpathString
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, String...)

selectNodeList

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

Any "{}" place-holder in the XPath expression is replaced with the content of the respective replacement string supplied in args. Please note that no escaping is performed on the replacement strings, beware of single and double quotes.

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, String...) or selectNodeList(Node, String, Node, String...).

It is better to use the selectListOfNodes(Node, String, 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
args - an optional array of strings used to replace the "{}" place-holders in xpathString
Returns:
all the nodes that match the given XPath expression
Throws:
XPathException
See Also:
selectListOfNodes(Node, String, String...)

selectNodeList

public static NodeList selectNodeList(Node contextNode,
                                      String xpathString,
                                      Node namespaceNode,
                                      String... args)
                               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, 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, 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
namespaceNode - the node from which all the namespace declarations will be taken
args - an optional array of strings used to replace the "{}" place-holders in xpathString
Returns:
all the nodes that match the given XPath expression
Throws:
XPathException
See Also:
selectListOfNodes(Node, String, Node, String...)

selectNodeList

public static NodeList selectNodeList(Node contextNode,
                                      String xpathString,
                                      Map<String,String> namespaces,
                                      String... args)
                               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, 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, 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
namespaces - a mapping between namespace prefixes and URIs
args - an optional array of strings used to replace the "{}" place-holders in xpathString
Returns:
all the nodes that match the given XPath expression
Throws:
XPathException
See Also:
selectListOfNodes(Node, String, Map, String...)

selectListOfNodes

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

Any "{}" place-holder in the XPath expression is replaced with the content of the respective replacement string supplied in args. Please note that no escaping is performed on the replacement strings, beware of single and double quotes.

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, String...) or selectListOfNodes(Node, String, Node, String...).

Parameters:
contextNode - the node from which the XPath expression is evaluated
xpathString - the XPath expression to evaluate
args - an optional array of strings used to replace the "{}" place-holders in xpathString
Returns:
all the nodes that match the given XPath expression
Throws:
XPathException

selectListOfNodes

public static List<Node> selectListOfNodes(Node contextNode,
                                           String xpathString,
                                           Node namespaceNode,
                                           String... args)
                                    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, 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
args - an optional array of strings used to replace the "{}" place-holders in xpathString
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,
                                           String... args)
                                    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, 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
args - an optional array of strings used to replace the "{}" place-holders in xpathString
Returns:
all the nodes that match the given XPath expression
Throws:
XPathException

selectNodeListAsStrings

public static List<String> selectNodeListAsStrings(Node contextNode,
                                                   String xpathString,
                                                   String... args)
                                            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, String...) or selectNodeListAsStrings(Node, String, Node, String...).

Parameters:
contextNode - the node from which the XPath expression is evaluated
xpathString - the XPath expression to evaluate
args - an optional array of strings used to replace the "{}" place-holders in xpathString
Returns:
a list with the textual content of the matching nodes
Throws:
XPathException
See Also:
selectNodeList(Node, String, String...)

selectNodeListAsStrings

public static List<String> selectNodeListAsStrings(Node contextNode,
                                                   String xpathString,
                                                   Map<String,String> namespaces,
                                                   String... args)
                                            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, 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 -
args - an optional array of strings used to replace the "{}" place-holders in xpathString
Returns:
a list with the textual content of the matching nodes
Throws:
XPathException
See Also:
selectNodeList(Node, String, Map, String...)

selectNodeListAsStrings

public static List<String> selectNodeListAsStrings(Node contextNode,
                                                   String xpathString,
                                                   Node namespaceNode,
                                                   String... args)
                                            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, 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
args - an optional array of strings used to replace the "{}" place-holders in xpathString
Returns:
a list with the textual content of the matching nodes
Throws:
XPathException
See Also:
selectNodeList(Node, String, Node, String...)

selectNodeIterator

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

Same as selectNodeList(Node, String, 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, String...).

Parameters:
contextNode - the node from which the XPath expression is evaluated
xpathString - the XPath expression to evaluate
args - an optional array of strings used to replace the "{}" place-holders in xpathString
Returns:
an iterator over all the nodes that match the given XPath expression
Throws:
XPathException
See Also:
selectNodeList(Node, String, String...)

selectNodeIterator

public static org.w3c.dom.traversal.NodeIterator selectNodeIterator(Node contextNode,
                                                                    String xpathString,
                                                                    Node namespaceNode,
                                                                    String... args)
                                                             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, String...) but returns a NodeIterator instead of a simple NodeList.

This function behaves like selectNodeIterator(Node, String, 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
args - an optional array of strings used to replace the "{}" place-holders in xpathString
Returns:
an iterator over all the nodes that match the given XPath expression
Throws:
XPathException
See Also:
selectNodeList(Node, String, Node, String...)


Copyright © 2011. All Rights Reserved.