Saxon.Api

 

 

Saxon.Api

Class XdmNode


public class XdmNode
extends XdmItem

The class XdmNode represents a Node in the XDM Data Model. A Node is an 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 Saxon.Hej.NodeInfo. Because this is a key interface within Saxon, it is exposed via this API, even though it is an internal interface that is not part of the API proper.

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, EnumerateAxis, which allows other nodes to be retrieved by following any of the XPath axes.

Navigation from a node to other related nodes can be achieved using the XdmValue.Select(Step) method, which this class inherits.

Constructor Summary

XdmNode (net.sf.saxon.om.NodeInfo node)

Construct an XdmNode as a wrapper around an instance of the internal class Saxon.Hej.om.NodeInfo

 

Property Summary

 Uri BaseUri

Get the base URI of the node.

 int ColumnNumber

Get the column number of the node in a source document.

 Uri DocumentUri

Get the document URI of the node.

 net.sf.saxon.om.NodeInfo Implementation

Escape hatch to the underlying class in the Java implementation

 int LineNumber

Get the line number of the node in a source document.

 XdmNodeKind NodeKind

The kind of node, as an instance of Saxon.Api.XdmNodeKind.

 QName NodeName

The name of the node, as a QName. Returns null in the case of unnamed nodes.

 XmlNodeType NodeType

The kind of node, as an instance of System.Xml.XmlNodeType.

 XdmNode OutermostElement

Get the outermost element of the tree containing this node.

 string OuterXml

Return a serialization of this node as lexical XML

 XdmNode Parent

Get the parent of this node.

 Processor Processor

Get a XdmNode.Processor suitable for use with this XdmNode.

 XdmNode Root

Get the root of the tree containing this node.

 QName TypeAnnotationName

The name of the type annotation of the node.

 XdmValue TypedValue

The typed value of the node, as an instance of XdmValue.

 

Method Summary

 IEnumerable<XdmNode> Children (Predicate<XdmNode> filter)

Get the nodes found on the child axis that satisfy a supplied Predicate.

 IEnumerable<XdmNode> Children ()

Get the element children of this node

 IEnumerable<XdmNode> Children (string localName)

Get the element children of this node having a specified local name, irrespective of the namespace

 IEnumerable<XdmNode> Children (string uri, string localName)

Get the element children having a specified namespace URI and local name

 IEnumerable<XdmNode> EnumerableOverAxis (XdmAxis axis)

Get an enumerable that supplies all the nodes on one of the XPath axes, starting with this node.

 IEnumerator<XdmNode> EnumerateAxis (XdmAxis axis)

Get an enumerator that supplies all the nodes on one of the XPath axes, starting with this node.

 IEnumerator<XdmNode> EnumerateAxis (XdmAxis axis, QName nodeName)

Get an enumerator that selects all the nodes on one of the XPath axes, provided they have a given name. The nodes selected are those of the principal node kind (elements for most axes, attributes for the attribute axis, namespace nodes for the namespace axis) whose name matches the name given in the second argument.

 bool Equals (object obj)

Two instances of XdmNode are equal if they represent the same node. That is, the Equals() method returns the same result as the XPath "is" operator.

 string GetAttributeValue (QName name)

Get a the string value of a named attribute of this element.

 string GetAttributeValue (string name)

Get a the string value of a named attribute (in no namespace) of this element.

 int GetHashCode ()

The hash code of a node reflects the equality relationship: if two XdmNode instances represent the same node, then they have the same hash code

 XmlNode GetUnderlyingXmlNode ()

Unwraps the underlying DOM XmlNode object from this XdmNode. If the method does not wrap a DOM XmlNode then null is returned

 XmlNode getUnderlyingXmlNode ()

Deprecated This is an obsolete synonym of GetUnderlyingXmlNode

 XNode GetUnderlyingXNode ()

Unwraps the underlying Linq XNode object from this XdmNode. If the method does not wrap a Linq XNode then null is returned

 bool IsAtomic ()

Determine whether the item is an atomic value

 IEnumerable<XdmNode> Select (Step<XdmNodeXdmNode> step)

Get a IEnumerable of XdmNodes by applying a Step to this XdmNode value.

 string ToString ()

Return a string representation of the node.

 void WriteTo (XmlWriter writer)

Send the node (that is, the subtree rooted at this node) to an XmlWriter

 

Constructor Detail

XdmNode

public XdmNode(net.sf.saxon.om.NodeInfo node)

Construct an XdmNode as a wrapper around an instance of the internal class Saxon.Hej.om.NodeInfo

Applications using the class Saxon.Hej.om.NodeInfo should be aware that it is subject to occasional changes from one release to the next. For documentation on this class, see the Saxon-EE Javadoc documentation for the very similar class net.sf.saxon.om.NodeInfo.

Parameters:

node - The object to be wrapped

Property Detail

BaseUri

public Uri BaseUri {get; }

Get the base URI of the node.

ColumnNumber

public int ColumnNumber {get; }

Get the column number of the node in a source document.

For a document constructed using the document builder, this is available only if the line numbering option was set when the document was built (and then only for element nodes). If the column number is not available, the value -1 is returned. Column numbers will be as reported by the XML parser; the Microsoft XML parser reports the column number of the opening "<" of the start tag.

DocumentUri

public Uri DocumentUri {get; }

Get the document URI of the node.

Implementation

public net.sf.saxon.om.NodeInfo Implementation {get; }

Escape hatch to the underlying class in the Java implementation

LineNumber

public int LineNumber {get; }

Get the line number of the node in a source document.

For a document constructed using the document builder, this is available only if the line numbering option was set when the document was built (and then only for element nodes). If the line number is not available, the value -1 is returned. Line numbers will be as reported by the XML parser; the Microsoft XML parser reports the line number of the opening "<" of the start tag.

NodeKind

public XdmNodeKind NodeKind {get; }

The kind of node, as an instance of Saxon.Api.XdmNodeKind.

NodeName

public QName NodeName {get; }

The name of the node, as a QName. Returns null in the case of unnamed nodes.

NodeType

public XmlNodeType NodeType {get; }

The kind of node, as an instance of System.Xml.XmlNodeType.

For a namespace node in the XDM model, the value XmlNodeType.None is returned.

OutermostElement

public XdmNode OutermostElement {get; }

Get the outermost element of the tree containing this node.

If this node is a document node, the property returns the first element child of the document node. Any subsequent element children are ignored. If there are no element children, the method returns null.

In all other cases, the property returns the value of ancestor-or-self::*[last()], that is the outermost element ancestor of the starting node if there is one, or null otherwise.

OuterXml

public string OuterXml {get; }

Return a serialization of this node as lexical XML

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.

Other nodes, such as text nodes, comments, and processing instructions, are represented as they would appear in lexical XML.

Parent

public XdmNode Parent {get; }

Get the parent of this node.

Returns either a document node, an element node, or null in the case where this node has no parent.

Processor

public Processor Processor {get; }

Get a XdmNode.Processor suitable for use with this XdmNode.

In most cases this will be the original XdmNode.Processor object used to create the DocumentBuilder that built the document that contains this node. If that XdmNode.Processor is not available, it will be a compatible Processor, one that shares the same underlying net.sf.saxon.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.

Returns:

Returns a Processor suitable for performing further operations on this node, for example for creating a Serializer or an XPathCompiler.

Root

public XdmNode Root {get; }

Get the root of the tree containing this node.

Returns the root of the tree containing this node (which might be this node itself).

TypeAnnotationName

public QName TypeAnnotationName {get; }

The name of the type annotation of the node.

For elements and attributes, this will be the name of the schema type against which the node was validated; if the node has not been validated it will be xs:untyped for elements, and xs:untypedAtomic for attributes.

For a document node, the value will be xs:anyType if the document has been validated, or xs:untyped otherwise.

For any other kind of node, the value will be null.

If the node has been validated against an anonymous type in the schema, the result will be a system-generated name, with the namespace URI http://ns.saxonica.com/anonymous-type.

TypedValue

public XdmValue TypedValue {get; }

The typed value of the node, as an instance of XdmValue.

A DynamicError is thrown if the node has no typed value, as will be the case for an element with element-only content.

Method Detail

Children

public IEnumerable<XdmNode> Children(Predicate<XdmNode> filter)

Get the nodes found on the child axis that satisfy a supplied Predicate.

Parameters:

filter - the predicate to be applied

Returns:

an Iterable containing those nodes found on the child axis that satisfy the supplied predicate.

Children

public IEnumerable<XdmNode> Children()

Get the element children of this node

Returns:

an Iterable containing all nodes on the child axis.

Children

public IEnumerable<XdmNode> Children(string localName)

Get the element children of this node having a specified local name, irrespective of the namespace

Parameters:

localName - the local name of the child elements to be selected, or "*" to select all children that are element nodes

Returns:

an Iterable containing the element children of this node that have the required local name.

Children

public IEnumerable<XdmNode> Children(string uri,
string localName)

Get the element children having a specified namespace URI and local name

Parameters:

uri - the namespace URI of the child elements to be selected: supply a zero-length string to indicate the null namespace
localName - the local name of the child elements to be selected

Returns:

an Iterable containing the element children of this node that have the required local name and namespace URI.

EnumerableOverAxis

public IEnumerable<XdmNode> EnumerableOverAxis(XdmAxis axis)

Get an enumerable that supplies all the nodes on one of the XPath axes, starting with this node.

The nodes are returned in axis order: that is, document order for a forwards axis, reverse document order for a reverse axis.

Parameters:

axis -  The axis to be navigated, for example XdmAxis.Child for the child axis.

EnumerateAxis

public IEnumerator<XdmNode> EnumerateAxis(XdmAxis axis)

Get an enumerator that supplies all the nodes on one of the XPath axes, starting with this node.

The nodes are returned in axis order: that is, document order for a forwards axis, reverse document order for a reverse axis.

Parameters:

axis -  The axis to be navigated, for example XdmAxis.Child for the child axis.

EnumerateAxis

public IEnumerator<XdmNode> EnumerateAxis(XdmAxis axis,
QName nodeName)

Get an enumerator that selects all the nodes on one of the XPath axes, provided they have a given name. The nodes selected are those of the principal node kind (elements for most axes, attributes for the attribute axis, namespace nodes for the namespace axis) whose name matches the name given in the second argument.

The nodes are returned in axis order: that is, document order for a forwards axis, reverse document order for a reverse axis.

Parameters:

axis -  The axis to be navigated, for example XdmAxis.Child for the child axis.
nodeName -  The name of the required nodes, for example new QName("", "item") to select nodes with local name "item", in no namespace.

Equals

public override bool Equals(object obj)

Two instances of XdmNode are equal if they represent the same node. That is, the Equals() method returns the same result as the XPath "is" operator.

Parameters:

obj - The object node to be compared

GetAttributeValue

public string GetAttributeValue(QName name)

Get a the string value of a named attribute of this element.

Returns null if this node is not an element, or if this element has no attribute with the specified name.

Parameters:

name - The name of the attribute whose value is required

GetAttributeValue

public string GetAttributeValue(string name)

Get a the string value of a named attribute (in no namespace) of this element.

Returns null if this node is not an element, or if this element has no attribute with the specified name.

Parameters:

name - The name of the attribute whose value is required, interpreted as no-namespace name

GetHashCode

public override int GetHashCode()

The hash code of a node reflects the equality relationship: if two XdmNode instances represent the same node, then they have the same hash code

GetUnderlyingXmlNode

public XmlNode GetUnderlyingXmlNode()

Unwraps the underlying DOM XmlNode object from this XdmNode. If the method does not wrap a DOM XmlNode then null is returned

Returns:

The underlying XmlNode

getUnderlyingXmlNode

public XmlNode getUnderlyingXmlNode()

Deprecated This is an obsolete synonym of GetUnderlyingXmlNode

Incorrectly-named synonym of GetUnderlyingXmlNode, retained temporarily for compatibility with 11.0 and 11.1

Returns:

The underlying XmlNode if there is one

GetUnderlyingXNode

public XNode GetUnderlyingXNode()

Unwraps the underlying Linq XNode object from this XdmNode. If the method does not wrap a Linq XNode then null is returned

The result will always be null if the supplied node is an attribute or namespace node, even if it is within a tree that wraps a Linq tree.

Returns:

The underlying XNode if there is one, or null otherwise

IsAtomic

public override bool IsAtomic()

Determine whether the item is an atomic value

Returns:

false (the item is not an atomic value)

Select

public IEnumerable<XdmNode> Select(Step<XdmNodeXdmNode> step)

Get a IEnumerable of XdmNodes by applying a Step to this XdmNode value.

Parameters:

step - the Step to be applied to this node

Returns:

an IEnumerable of nodes obtained by applying the Step function to this node

ToString

public override string ToString()

Return a string representation of the node.

This method returns the value of the XdmNode.OuterXml property, that is, a serialization of the node. To get the string value of a node as defined in XPath, use the XdmItem.StringValue property.

WriteTo

public void WriteTo(XmlWriter writer)

Send the node (that is, the subtree rooted at this node) to an XmlWriter

Note that an XmlWriter can only handle a well-formed XML document. This method will therefore signal an exception if the node is a document node with no children, or with more than one element child.

Parameters:

writer -  The XmlWriter to which the node is to be written