Interface for navigating around the W3C DOM Level 2 object model.
This class is not intended for direct usage, but is
used by the Jaxen engine during evaluation.
This class implements the
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
NamespaceNode
class, and
users will have to check result sets to locate and isolate
these.
getAttributeName
public String getAttributeName(Object attribute)
Get the local name of an attribute.
- getAttributeName in interface Navigator
attribute
- the target node
- a string representing the unqualified local name
if the node is an attribute, or null otherwise
getAttributeNamespaceUri
public String getAttributeNamespaceUri(Object attribute)
Get the namespace URI of an attribute.
- getAttributeNamespaceUri in interface Navigator
attribute
- the target node
- the namespace name of the specified node
getAttributeQName
public String getAttributeQName(Object attribute)
Get the qualified name of an attribute.
- getAttributeQName in interface Navigator
attribute
- the target node
- a string representing the qualified (i.e. possibly
prefixed) name if the argument is an attribute, or null otherwise
getAttributeStringValue
public String getAttributeStringValue(Object object)
Get the string value of an attribute node.
- getAttributeStringValue in interface Navigator
- the text of the attribute value if the node is an
attribute, null otherwise
getCommentStringValue
public String getCommentStringValue(Object object)
Get the string value of a comment node.
- getCommentStringValue in interface Navigator
- the text of the comment if the node is a comment, null otherwise
getElementById
public Object getElementById(Object object,
String elementId)
Returns the element whose ID is given by elementId.
If no such element exists, returns null.
Attributes with the name "ID" are not of type ID unless so defined.
Attribute types are only known if when the parser understands DTD's or
schemas that declare attributes of type ID. When JAXP is used, you
must call setValidating(true)
on the
DocumentBuilderFactory.
- getElementById in interface Navigator
- getElementById in interface DefaultNavigator
object
- a node from the document in which to look for the idelementId
- id to look for
- 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
javax.xml.parsers.DocumentBuilderFactory
getElementName
public String getElementName(Object element)
Get the local name of an element.
- getElementName in interface Navigator
element
- the target node
- a string representing the unqualified local name
if the node is an element, or null otherwise
getElementNamespaceUri
public String getElementNamespaceUri(Object element)
Get the namespace URI of an element.
- getElementNamespaceUri in interface Navigator
element
- the target node
- a string (possibly empty) if the node is an element,
and null otherwise
getElementQName
public String getElementQName(Object element)
Get the qualified name of an element.
- getElementQName in interface Navigator
element
- the target node
- a string representing the qualified (i.e. possibly
prefixed) name if the argument is an element, or null otherwise
getElementStringValue
public String getElementStringValue(Object object)
Get the string value of an element node.
- getElementStringValue in interface Navigator
- the text inside the node and its descendants if the node
is an element, null otherwise
getInstance
public static Navigator getInstance()
Get a constant DocumentNavigator for efficiency.
- a constant instance of a DocumentNavigator.
getNamespaceAxisIterator
public Iterator getNamespaceAxisIterator(Object contextNode)
Get an iterator over all declared namespaces.
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.
- getNamespaceAxisIterator in interface Navigator
- getNamespaceAxisIterator in interface DefaultNavigator
contextNode
- the context node for the namespace axis
- a possibly-empty iterator (not null)
getNamespacePrefix
public String getNamespacePrefix(Object object)
Get the prefix value of a namespace node.
- getNamespacePrefix in interface Navigator
- the namespace prefix a (possibly empty) string if the
node is a namespace node, null otherwise
getNamespaceStringValue
public String getNamespaceStringValue(Object object)
Get the string value of a namespace node.
- getNamespaceStringValue in interface Navigator
- the namespace URI as a (possibly empty) string if the
node is a namespace node, null otherwise
getParentNode
public Object getParentNode(Object o)
Return the XPath parent of this DOM node.
XPath has slightly different definition of parent than DOM does.
In particular, the parent of an attribute is not null.
- getParentNode in interface Navigator
- getParentNode in interface DefaultNavigator
- the parent of the specified node; or null if
the node does not have a parent
getStringValue
private StringBuffer getStringValue(Node node,
StringBuffer buffer)
Construct a node's string value recursively.
node
- the current nodebuffer
- the buffer for building the text
- the buffer passed as a parameter (for convenience)
getTextStringValue
public String getTextStringValue(Object object)
Get the string value of text.
- getTextStringValue in interface Navigator
- the string of text if the node is text, null otherwise
isAttribute
public boolean isAttribute(Object object)
Test if a node is an attribute. xmlns
and
xmlns:pre
attributes do not count as attributes
for the purposes of XPath.
- isAttribute in interface Navigator
- true if the node is an attribute, false otherwise
isComment
public boolean isComment(Object object)
Test if a node is a comment.
- isComment in interface Navigator
- true if the node is a comment, false otherwise
isDocument
public boolean isDocument(Object object)
Test if a node is a top-level document.
- isDocument in interface Navigator
- true if the node is the document root, false otherwise
isElement
public boolean isElement(Object object)
Test if a node is an element.
- isElement in interface Navigator
- true if the node is an element, false otherwise
isNamespace
public boolean isNamespace(Object object)
Test if a node is a namespace.
- isNamespace in interface Navigator
- true if the node is a namespace, false otherwise
isProcessingInstruction
public boolean isProcessingInstruction(Object object)
Test if a node is a processing instruction.
- isProcessingInstruction in interface Navigator
- true if the node is a processing instruction, false otherwise
isText
public boolean isText(Object object)
Test if a node is plain text.
- isText in interface Navigator
- true if the node is a text node, false otherwise
parseXPath
public XPath parseXPath(String xpath)
throws SAXPathException
Returns a parsed form of the given XPath string, which will be suitable
for queries on DOM documents.
- parseXPath in interface Navigator
xpath
- the XPath expression
- a parsed form of the given XPath string