public class XdmNode extends XdmItem
XdmItem
, and is therefore an
XdmValue
in its own right, and may also participate as one item within a sequence value.
An XdmNode is implemented as a wrapper around an object of type NodeInfo
.
Because this is a key interface within Saxon, it is exposed via this API.
The XdmNode interface exposes basic properties of the node, such as its name, its string value, and
its typed value. Navigation to other nodes is supported through a single method, axisIterator(net.sf.saxon.s9api.Axis)
,
which allows other nodes to be retrieved by following any of the XPath axes.
Note that node identity cannot be inferred from object identity. The same node may be represented
by different XdmNode
instances at different times, or even at the same time. The equals()
method on this class can be used to test for node identity.
Constructor and Description |
---|
XdmNode(NodeInfo node)
Construct an XdmNode as a wrapper around an existing NodeInfo object
|
Modifier and Type | Method and Description |
---|---|
javax.xml.transform.Source |
asSource()
Get a JAXP Source object corresponding to this node, allowing the node to be
used as input to transformations or queries.
|
java.lang.String |
attribute(java.lang.String name)
Get the string value of a named attribute (in no namespace) of this element
|
XdmSequenceIterator<XdmNode> |
axisIterator(Axis axis)
Get an iterator over the nodes reachable from this node via a given axis.
|
XdmSequenceIterator<XdmNode> |
axisIterator(Axis axis,
QName name)
Get an iterator over the nodes reachable from this node via a given axis, selecting only
those nodes with a specified name.
|
java.lang.Iterable<XdmNode> |
children()
Get the children of this node
|
java.lang.Iterable<XdmNode> |
children(java.util.function.Predicate<? super XdmNode> filter)
Get the nodes found on the child axis that satisfy a supplied
Predicate . |
java.lang.Iterable<XdmNode> |
children(java.lang.String localName)
Get the element children of this node having a specified
local name, irrespective of the namespace
|
java.lang.Iterable<XdmNode> |
children(java.lang.String uri,
java.lang.String localName)
Get the element children having a specified namespace URI and local name
|
boolean |
equals(java.lang.Object other)
The
equals() relation between two XdmNode objects is true if they both represent the same
node. |
java.lang.String |
getAttributeValue(QName name)
Get the string value of a named attribute of this element
|
java.net.URI |
getBaseURI()
Get the base URI of this node
|
int |
getColumnNumber()
Get the column number of the node in a source document.
|
java.net.URI |
getDocumentURI()
Get the document URI of this node.
|
java.lang.Object |
getExternalNode()
In the case of an XdmNode that wraps a node in an external object model such as DOM, JDOM,
XOM, or DOM4J, get the underlying wrapped node
|
int |
getLineNumber()
Get the line number of the node in a source document.
|
XdmNodeKind |
getNodeKind()
Get the kind of node.
|
QName |
getNodeName()
Get the name of the node, as a QName
|
XdmNode |
getParent()
Get the parent of this node
|
Processor |
getProcessor()
|
XdmNode |
getRoot()
Get the root of the tree containing this node (which may or may not be a document node)
|
XdmValue |
getTypedValue()
Get the typed value of this node, as defined in XDM
|
NodeInfo |
getUnderlyingNode()
Get the underlying Saxon implementation object representing this node.
|
NodeInfo |
getUnderlyingValue()
Get the underlying implementation object representing the value.
|
int |
hashCode()
The hashcode is such that two XdmNode instances have the same hashCode if they represent the same
node.
|
XdmSequenceIterator<XdmNode> |
nodeIterator() |
XdmStream<XdmNode> |
stream()
Get a stream comprising the items in this value
|
java.lang.String |
toString()
The toString() method returns a simple XML serialization of the node
with defaulted serialization parameters.
|
asMap, getStringValue, isAtomicValue, matches, size, wrapItem, wrapItem, wrapItem
append, documentOrder, fromGroundedValue, itemAt, iterator, makeSequence, makeValue, select, setValue, wrap, wrap
public XdmNode(NodeInfo node)
node
- the NodeInfo object to be wrapped. This can be retrieved using the
getUnderlyingNode()
method.public XdmNodeKind getNodeKind()
XdmNodeKind.ELEMENT
or XdmNodeKind.ATTRIBUTE
public Processor getProcessor()
Processor
suitable for use with this XdmNode
.
In most cases this will be the original Processor
object used to create
the DocumentBuilder
that built the document that contains this node. If
that Processor
is not available, it will be a compatible Processor
,
one that shares the same underlying Configuration
, and hence is initialized
with the same configuration settings, schema components, license features, and so on.
Note: the only case where the original Processor
is not available is when
the same Configuration
is used with multiple APIs, for example mixing s9api
and JAXP or XQJ in the same application.
Serializer
or an XPathCompiler
.public NodeInfo getUnderlyingValue()
getUnderlyingValue
in class XdmItem
public QName getNodeName()
public XdmValue getTypedValue() throws SaxonApiException
XdmAtomicValue
SaxonApiException
- if an error occurs obtaining the typed value, for example because
the node is an element with element-only contentpublic int getLineNumber()
public int getColumnNumber()
public javax.xml.transform.Source asSource()
The Source object that is returned will generally be one that is acceptable to Saxon interfaces
that expect an instance of javax.xml.transform.Source
. However, there is no guarantee
that it will be recognized by other products.
In fact, the current implementation always returns an instance of
net.sf.saxon.om.NodeInfo
.
public java.lang.Iterable<XdmNode> children()
Iterable
containing all nodes on the child axispublic java.lang.Iterable<XdmNode> children(java.lang.String localName)
localName
- the local name of the child elements to be selected,
or "*" to select all children that are element nodesIterable
containing the element children of this node that have the
required local name.public java.lang.Iterable<XdmNode> children(java.lang.String uri, java.lang.String localName)
uri
- the namespace URI of the child elements to be selected:
supply a zero-length string to indicate the null namespacelocalName
- the local name of the child elements to be selectedIterable
containing the element children of this node that have the
required local name and namespace URI.public java.lang.Iterable<XdmNode> children(java.util.function.Predicate<? super XdmNode> filter)
Predicate
.filter
- the predicate to be appliedIterable
containing those nodes found on the child axis that satisfy the supplied Predicate
.public XdmSequenceIterator<XdmNode> axisIterator(Axis axis)
axis
- identifies which axis is to be navigatedpublic XdmSequenceIterator<XdmNode> axisIterator(Axis axis, QName name)
axis
- identifies which axis is to be navigatedname
- identifies the name of the nodes to be selected. The selected nodes will be those
whose node kind is the principal node kind of the axis (that is, attributes for the attribute
axis, namespaces for the namespace axis, and elements for all other axes) whose name matches
the specified name.
For example, specify new QName("", "item")
to select nodes with local name
"item", in no namespace.
public XdmNode getParent()
public XdmNode getRoot()
public java.lang.String getAttributeValue(QName name)
name
- the name of the required attributepublic java.lang.String attribute(java.lang.String name)
name
- the name of the required attribute, interpreted as a no-namespace namepublic java.net.URI getBaseURI()
java.lang.IllegalStateException
- if the base URI property of the underlying node is not a valid URI.public java.net.URI getDocumentURI()
java.lang.IllegalStateException
- if the document URI property of the underlying node is not a valid URI.public int hashCode()
hashCode
in class java.lang.Object
public boolean equals(java.lang.Object other)
equals()
relation between two XdmNode objects is true if they both represent the same
node. That is, it corresponds to the "is" operator in XPath.equals
in class java.lang.Object
other
- the object to be comparedpublic java.lang.String toString()
In the case of an element node, the result will be a well-formed XML document serialized as defined in the W3C XSLT/XQuery serialization specification, using options method="xml", indent="yes", omit-xml-declaration="yes".
In the case of a document node, the result will be a well-formed XML document provided that the document node contains exactly one element child, and no text node children. In other cases it will be a well-formed external general parsed entity.
In the case of an attribute node, the output is a string in the form
name="value"
. The name will use the original namespace prefix.
In the case of a namespace node, the output is a string in the form of a namespace
declaration, that is xmlns="uri"
or xmlns:pre="uri"
.
Other nodes, such as text nodes, comments, and processing instructions, are
represented as they would appear in lexical XML. Note: this means that in the case
of text nodes, special characters such as &
and <
are output in escaped form. To get the unescaped string value of a text node, use
XdmItem.getStringValue()
instead.
For more control over serialization, use the Serializer
class.
public NodeInfo getUnderlyingNode()
public java.lang.Object getExternalNode()
public XdmSequenceIterator<XdmNode> nodeIterator()
Copyright (c) 2004-2020 Saxonica Limited. All rights reserved.