org.jaxen.dom
public class DocumentNavigator extends DefaultNavigator
This class is not intended for direct usage, but is used by the Jaxen engine during evaluation.
This class implements the {@link org.jaxen.DefaultNavigator} interface for the Jaxen XPath library. This adapter allows the Jaxen library to be used to execute XPath queries against any object tree that implements the DOM level 2 interfaces.
Note: DOM level 2 does not include a node representing an XPath namespace node. This navigator will return namespace nodes as instances of the custom {@link NamespaceNode} class, and users will have to check result sets to locate and isolate these.
See Also: XPath NamespaceNode
Nested Class Summary | |
---|---|
static class | DocumentNavigator.AttributeIterator
An iterator over an attribute list. |
abstract class | DocumentNavigator.NodeIterator
A generic iterator over DOM nodes.
|
Field Summary | |
---|---|
static long | serialVersionUID |
static DocumentNavigator | SINGLETON |
Constructor Summary | |
---|---|
DocumentNavigator()
Default constructor. |
Method Summary | |
---|---|
Iterator | getAttributeAxisIterator(Object contextNode)
Get an iterator over all attributes.
|
String | getAttributeName(Object attribute)
Get the local name of an attribute.
|
String | getAttributeNamespaceUri(Object attribute)
Get the namespace URI of an attribute.
|
String | getAttributeQName(Object attribute)
Get the qualified name of an attribute.
|
String | getAttributeStringValue(Object object)
Get the string value of an attribute node.
|
Iterator | getChildAxisIterator(Object contextNode)
Get an iterator over all of this node's children.
|
String | getCommentStringValue(Object object)
Get the string value of a comment node.
|
Object | getDocument(String uri)
Use JAXP to load a namespace aware document from a given URI.
|
Object | getDocumentNode(Object contextNode)
Get the top-level document node.
|
Object | getElementById(Object object, String elementId)
Returns the element whose ID is given by elementId.
|
String | getElementName(Object element)
Get the local name of an element.
|
String | getElementNamespaceUri(Object element)
Get the namespace URI of an element.
|
String | getElementQName(Object element)
Get the qualified name of an element.
|
String | getElementStringValue(Object object)
Get the string value of an element node.
|
Iterator | getFollowingAxisIterator(Object contextNode)
Get an iterator over all following nodes, depth-first.
|
Iterator | getFollowingSiblingAxisIterator(Object contextNode)
Get an iterator over all following siblings.
|
static Navigator | getInstance()
Get a constant DocumentNavigator for efficiency.
|
Iterator | getNamespaceAxisIterator(Object contextNode)
Get an iterator over all declared namespaces.
|
String | getNamespacePrefix(Object object)
Get the prefix value of a namespace node.
|
String | getNamespaceStringValue(Object object)
Get the string value of a namespace node.
|
Iterator | getParentAxisIterator(Object contextNode)
Get a (single-member) iterator over this node's parent.
|
Object | getParentNode(Object o)
Return the XPath parent of this DOM node.
|
Iterator | getPrecedingSiblingAxisIterator(Object contextNode)
Get an iterator over all preceding siblings.
|
String | getProcessingInstructionData(Object obj)
Get the data of a processing instruction node.
|
String | getProcessingInstructionTarget(Object obj)
Get the target of a processing instruction node.
|
StringBuffer | getStringValue(Node node, StringBuffer buffer)
Construct a node's string value recursively.
|
String | getTextStringValue(Object object)
Get the string value of text.
|
boolean | isAttribute(Object object)
Test if a node is an attribute. |
boolean | isComment(Object object)
Test if a node is a comment.
|
boolean | isDocument(Object object)
Test if a node is a top-level document.
|
boolean | isElement(Object object)
Test if a node is an element.
|
boolean | isNamespace(Object object)
Test if a node is a namespace.
|
boolean | isProcessingInstruction(Object object)
Test if a node is a processing instruction.
|
boolean | isText(Object object)
Test if a node is plain text.
|
XPath | parseXPath(String xpath) Returns a parsed form of the given XPath string, which will be suitable
for queries on DOM documents.
|
String | translateNamespacePrefixToUri(String prefix, Object element)
Translate a namespace prefix to a URI.
|
Parameters: contextNode the context node for the attribute axis
Returns: a possibly-empty iterator (not null)
Parameters: attribute the target node
Returns: a string representing the unqualified local name if the node is an attribute, or null otherwise
Parameters: attribute the target node
Returns: the namespace name of the specified node
Parameters: attribute the target node
Returns: a string representing the qualified (i.e. possibly prefixed) name if the argument is an attribute, or null otherwise
Parameters: object the target node
Returns: the text of the attribute value if the node is an attribute, null otherwise
Parameters: contextNode the context node for the child axis.
Returns: a possibly-empty iterator (not null)
Parameters: object the target node
Returns: the text of the comment if the node is a comment, null otherwise
Parameters: uri the URI of the document to load
Returns: the new W3C DOM Level 2 Document instance
Throws: FunctionCallException containing a nested exception if a problem occurs trying to parse the given document
Parameters: contextNode any node in the document
Returns: the root node
setValidating(true)
on the
DocumentBuilderFactory.
Parameters: object a node from the document in which to look for the id elementId id to look for
Returns: element whose ID is given by elementId, or null if no such element exists in the document or if the implementation does not know about attribute types
Throws: ClassCastException if object is not an org.w3c.dom.Node object
See Also: javax.xml.parsers.DocumentBuilderFactory
Parameters: element the target node
Returns: a string representing the unqualified local name if the node is an element, or null otherwise
Parameters: element the target node
Returns: a string (possibly empty) if the node is an element, and null otherwise
Parameters: element the target node
Returns: a string representing the qualified (i.e. possibly prefixed) name if the argument is an element, or null otherwise
Parameters: object the target node
Returns: the text inside the node and its descendants if the node is an element, null otherwise
Parameters: contextNode the context node for the following axis
Returns: a possibly-empty iterator (not null)
Parameters: contextNode the context node for the sibling iterator
Returns: a possibly-empty iterator (not null)
Returns: a constant instance of a DocumentNavigator.
Note: this iterator is not live: it takes a snapshot and that snapshot remains static during the life of the iterator (i.e. it won't reflect subsequent changes to the DOM).
In the event that the DOM is inconsistent; for instance a
pre:foo
element is declared by DOM to be in the
http://www.a.com/ namespace but also has an
xmlns:pre="http://www.b.com"
attribute; then only
one of the namespaces will be counted. This will be the intrinsic
namespace of the Element
or Attr
object
rather than the one provide by the contradictory namespace
declaration attribute. In the event of a contradiction between two
attributes on the same element--e.g. pre:foo
in the
http://www.a.com/ namespace and pre:bar
in the
http://www.b.com/ namespace--it is undefined which namespace
will be returned.
Parameters: contextNode the context node for the namespace axis
Returns: a possibly-empty iterator (not null)
Parameters: object the target node
Returns: the namespace prefix a (possibly empty) string if the node is a namespace node, null otherwise
Parameters: object the target node
Returns: the namespace URI as a (possibly empty) string if the node is a namespace node, null otherwise
Parameters: contextNode the context node for the parent axis
Returns: a possibly-empty iterator (not null)
Parameters: o
Returns: the parent of the specified node; or null if the node does not have a parent
Parameters: contextNode the context node for the preceding sibling axis
Returns: a possibly-empty iterator (not null)
Parameters: obj the processing instruction
Returns: the target of the processing instruction
Throws: ClassCastException if obj is not a processing instruxtion
Parameters: obj the processing instruction
Returns: the target of the processing instruction
Throws: ClassCastException if obj is not a processing instruxtion
Parameters: node the current node buffer the buffer for building the text
Returns: the buffer passed as a parameter (for convenience)
Parameters: object the target node
Returns: the string of text if the node is text, null otherwise
xmlns
and
xmlns:pre
attributes do not count as attributes
for the purposes of XPath.
Parameters: object the target node
Returns: true if the node is an attribute, false otherwise
Parameters: object the target node
Returns: true if the node is a comment, false otherwise
Parameters: object the target node
Returns: true if the node is the document root, false otherwise
Parameters: object the target node
Returns: true if the node is an element, false otherwise
Parameters: object the target node
Returns: true if the node is a namespace, false otherwise
Parameters: object the target node
Returns: true if the node is a processing instruction, false otherwise
Parameters: object the target node
Returns: true if the node is a text node, false otherwise
Parameters: xpath the XPath expression
Returns: a parsed form of the given XPath string
Throws: org.jaxen.saxpath.SAXPathException if the string is syntactically incorrect
Parameters: prefix the namespace prefix element the namespace context
Returns: the namespace URI bound to the prefix in the scope of element
;
null if the prefix is not bound