Top Description Methods
org.dom4j

public Interface XPath

extends NodeFilter
Known Direct Implementers
org.dom4j.xpath.DefaultXPath
Annotations
@SuppressWarnings:unused
Imports
org.jaxen.FunctionContext, .NamespaceContext, .VariableContext, java.util.List, .Map

XPath represents an XPath expression after it has been parsed from a String.
Author
James Strachan
Version
$Revision: 1.20 $

Method Summary

Modifier and TypeMethod and Description
public boolean

Returns:

The boolean-value interpretation of this expression.
booleanValueOf
(Object
The node, nodeset or Context object for evaluation. This value can be null
context
)

Retrieve a boolean-value interpretation of this XPath expression when evaluated against a given context.

public Object

Returns:

the value of the XPath expression as a Listof Node instances, a Nodeinstance, a Stringor a Numberinstance depending on the XPath expression.
evaluate
(Object
is either a node or a list of nodes on which to evalute the XPath
context
)

evaluate evaluates an XPath expression and returns the result as an Object.

public FunctionContext

Returns:

the current function context
getFunctionContext
()

DOCUMENT ME!

public NamespaceContext

Returns:

the current namespace context
getNamespaceContext
()

DOCUMENT ME!

public String

Returns:

the textual format of the XPath expression.
getText
()

getText will return the textual version of the XPath expression.

public VariableContext

Returns:

the current variable context
getVariableContext
()

DOCUMENT ME!

public boolean

Returns:

true if the given node matches this XPath expression
matches
(Node
DOCUMENT ME!
node
)

Redeclares org.dom4j.NodeFilter.matches.

matches returns true if the given node matches the XPath expression.
public Number

Returns:

the numeric result of the XPath expression or null if the result is not a number.
numberValueOf
(Object
is either a node or a list of nodes on which to evalute the XPath
context
)

numberValueOf evaluates an XPath expression and returns the numeric value of the XPath expression if the XPath expression results is a number, or null if the result is not a number.

public List<Node>

Returns:

the results of all the XPath evaluations as a single list
selectNodes
(Object
is either a node or a list of nodes on which to evalute the XPath
context
)

selectNodes performs this XPath expression on the given Nodeor Listof Nodes instances appending all the results together into a single list.

public List<Node>

Returns:

a list of Node instances
selectNodes
(Object
is either a node or a list of nodes on which to evalute the XPath
context
,
XPath
is the XPath expression to sort by
sortXPath
)

selectNodes evaluates the XPath expression on the given Nodeor Listof Nodes and returns the result as a List of Node s sorted by the sort XPath expression.

public List<Node>

Returns:

a list of Node instances
selectNodes
(Object
is either a node or a list of nodes on which to evalute the XPath
context
,
XPath
is the XPath expression to sort by
sortXPath
,
boolean
specifies whether or not duplicate values of the sort expression are allowed. If this parameter is true then only distinct sort expressions values are included in the result
distinct
)

selectNodes evaluates the XPath expression on the given Nodeor Listof Nodes and returns the result as a List of Node s sorted by the sort XPath expression.

public Object

Returns:

the value of the XPath expression as a Listof Node instances, a Nodeinstance, a Stringor a Numberinstance depending on the XPath expression.
selectObject
(Object
is either a node or a list of nodes on which to evalute the XPath
context
)

Deprecated please use evaluate(Object) instead. WILL BE REMOVED IN dom4j-1.6 !!
selectObject evaluates an XPath expression and returns the result as an Object.
public Node

Returns:

a single matching Node instance
selectSingleNode
(Object
is either a node or a list of nodes on which to evalute the XPath
context
)

selectSingleNode evaluates this XPath expression on the given Nodeor Listof Nodes and returns the result as a single Node instance.

public void
setFunctionContext(FunctionContext
DOCUMENT ME!
functionContext
)

Sets the function context to be used when evaluating XPath expressions

public void
setNamespaceContext(NamespaceContext
DOCUMENT ME!
namespaceContext
)

Sets the namespace context to be used when evaluating XPath expressions

public void
setNamespaceURIs(Map<String, String>
the map containing the namespace mappings
map
)

Sets the current NamespaceContext from a Map where the keys are the String namespace prefixes and the values are the namespace URIs.

public void
setVariableContext(VariableContext
DOCUMENT ME!
variableContext
)

Sets the variable context to be used when evaluating XPath expressions

public void
sort(List<Node>
is the list of Nodes to sort
list
)

sort sorts the given List of Nodes using this XPath expression as a java.util.Comparator.

public void
sort(List<Node>
is the list of Nodes to sort
list
,
boolean
if true then duplicate values (using the sortXPath for comparisions) will be removed from the List
distinct
)

sort sorts the given List of Nodes using this XPath expression as a java.util.Comparatorand optionally removing duplicates.

public String

Returns:

the string representation of the results of the XPath expression
valueOf
(Object
is either a node or a list of nodes on which to evalute the XPath
context
)

valueOf evaluates this XPath expression and returns the textual representation of the results using the XPath string() function.

Method Detail

booleanValueOfback to summary
public boolean booleanValueOf(Object context)

Retrieve a boolean-value interpretation of this XPath expression when evaluated against a given context. The boolean-value of the expression is determined per the boolean(..) core function as defined in the XPath specification. This means that an expression that selects zero nodes will return false, while an expression that selects one-or-more nodes will return true.

Parameters
context:Object

The node, nodeset or Context object for evaluation. This value can be null

Returns:boolean

The boolean-value interpretation of this expression.

Since
1.5
evaluateback to summary
public Object evaluate(Object context)

evaluate evaluates an XPath expression and returns the result as an Object. The object returned can either be a List of Nodeinstances, a Nodeinstance, a String or a Numberinstance depending on the XPath expression.

Parameters
context:Object

is either a node or a list of nodes on which to evalute the XPath

Returns:Object

the value of the XPath expression as a Listof Node instances, a Nodeinstance, a Stringor a Numberinstance depending on the XPath expression.

getFunctionContextback to summary
public FunctionContext getFunctionContext()

DOCUMENT ME!

Returns:FunctionContext

the current function context

getNamespaceContextback to summary
public NamespaceContext getNamespaceContext()

DOCUMENT ME!

Returns:NamespaceContext

the current namespace context

getTextback to summary
public String getText()

getText will return the textual version of the XPath expression.

Returns:String

the textual format of the XPath expression.

getVariableContextback to summary
public VariableContext getVariableContext()

DOCUMENT ME!

Returns:VariableContext

the current variable context

matchesback to summary
public boolean matches(Node node)

Redeclares org.dom4j.NodeFilter.matches.

matches returns true if the given node matches the XPath expression. To be more precise when evaluating this XPath expression on the given node the result set must include the node.

Parameters
node:Node

DOCUMENT ME!

Returns:boolean

true if the given node matches this XPath expression

numberValueOfback to summary
public Number numberValueOf(Object context)

numberValueOf evaluates an XPath expression and returns the numeric value of the XPath expression if the XPath expression results is a number, or null if the result is not a number.

Parameters
context:Object

is either a node or a list of nodes on which to evalute the XPath

Returns:Number

the numeric result of the XPath expression or null if the result is not a number.

selectNodesback to summary
public List<Node> selectNodes(Object context)

selectNodes performs this XPath expression on the given Nodeor Listof Nodes instances appending all the results together into a single list.

Parameters
context:Object

is either a node or a list of nodes on which to evalute the XPath

Returns:List<Node>

the results of all the XPath evaluations as a single list

selectNodesback to summary
public List<Node> selectNodes(Object context, XPath sortXPath)

selectNodes evaluates the XPath expression on the given Nodeor Listof Nodes and returns the result as a List of Node s sorted by the sort XPath expression.

Parameters
context:Object

is either a node or a list of nodes on which to evalute the XPath

sortXPath:XPath

is the XPath expression to sort by

Returns:List<Node>

a list of Node instances

selectNodesback to summary
public List<Node> selectNodes(Object context, XPath sortXPath, boolean distinct)

selectNodes evaluates the XPath expression on the given Nodeor Listof Nodes and returns the result as a List of Node s sorted by the sort XPath expression.

Parameters
context:Object

is either a node or a list of nodes on which to evalute the XPath

sortXPath:XPath

is the XPath expression to sort by

distinct:boolean

specifies whether or not duplicate values of the sort expression are allowed. If this parameter is true then only distinct sort expressions values are included in the result

Returns:List<Node>

a list of Node instances

selectObjectback to summary
public Object selectObject(Object context)

Deprecated

please use evaluate(Object) instead. WILL BE REMOVED IN dom4j-1.6 !!

selectObject evaluates an XPath expression and returns the result as an Object. The object returned can either be a List of Nodeinstances, a Nodeinstance, a String or a Numberinstance depending on the XPath expression.

Parameters
context:Object

is either a node or a list of nodes on which to evalute the XPath

Returns:Object

the value of the XPath expression as a Listof Node instances, a Nodeinstance, a Stringor a Numberinstance depending on the XPath expression.

selectSingleNodeback to summary
public Node selectSingleNode(Object context)

selectSingleNode evaluates this XPath expression on the given Nodeor Listof Nodes and returns the result as a single Node instance.

Parameters
context:Object

is either a node or a list of nodes on which to evalute the XPath

Returns:Node

a single matching Node instance

setFunctionContextback to summary
public void setFunctionContext(FunctionContext functionContext)

Sets the function context to be used when evaluating XPath expressions

Parameters
functionContext:FunctionContext

DOCUMENT ME!

setNamespaceContextback to summary
public void setNamespaceContext(NamespaceContext namespaceContext)

Sets the namespace context to be used when evaluating XPath expressions

Parameters
namespaceContext:NamespaceContext

DOCUMENT ME!

setNamespaceURIsback to summary
public void setNamespaceURIs(Map<String, String> map)

Sets the current NamespaceContext from a Map where the keys are the String namespace prefixes and the values are the namespace URIs. For example:

Map uris = new HashMap();
uris.put("SOAP-ENV", "http://schemas.xmlsoap.org/soap/envelope/");
uris.put("m", "urn:xmethodsBabelFish");
XPath xpath = document
        .createXPath("SOAP-ENV:Envelope/SOAP-ENV:Body/m:BabelFish");
xpath.setNamespaceURIs(uris);
Node babelfish = xpath.selectSingleNode(document);
Parameters
map:Map<String, String>

the map containing the namespace mappings

setVariableContextback to summary
public void setVariableContext(VariableContext variableContext)

Sets the variable context to be used when evaluating XPath expressions

Parameters
variableContext:VariableContext

DOCUMENT ME!

sortback to summary
public void sort(List<Node> list)

sort sorts the given List of Nodes using this XPath expression as a java.util.Comparator.

Parameters
list:List<Node>

is the list of Nodes to sort

sortback to summary
public void sort(List<Node> list, boolean distinct)

sort sorts the given List of Nodes using this XPath expression as a java.util.Comparatorand optionally removing duplicates.

Parameters
list:List<Node>

is the list of Nodes to sort

distinct:boolean

if true then duplicate values (using the sortXPath for comparisions) will be removed from the List

valueOfback to summary
public String valueOf(Object context)

valueOf evaluates this XPath expression and returns the textual representation of the results using the XPath string() function.

Parameters
context:Object

is either a node or a list of nodes on which to evalute the XPath

Returns:String

the string representation of the results of the XPath expression