NodeInfo interface

The NodeInfo interface (net.sf.saxon.om.NodeInfo on Java, or Saxon.Hej.om.NodeInfo on C#) represents a node of an XML document. The methods on this class follow the XPath data model closely.

The most commonly used methods on NodeInfo include:

getNodeKind()

Gets a short identifying the node type (for example, element or attribute). The values are consistent with those used in the DOM, and are referenced by constants in the class net.sf.saxon.type.Type.

getDisplayName(), getLocalPart(), getPrefix(), getURI()

These methods get the name of an element or attribute, or its various parts. The getDisplayName() method returns the QName as used in the original source XML.

getAttributeValue()

Gets the value of a specified attribute, as a String.

getStringValue()

Gets the string value of a node, as defined in the XPath data model.

getUnicodeStringValue()

Gets the string value of a node, as a UnicodeString. This is a Saxon-specific string representation designed to be more efficient that the system String class for many common operations, especially when it contains characters with codepoints above 65535.

atomize()

Gets the typed value of a node, as defined in the XPath 2.0 data model. This is in general a sequence of atomic values, so the result is an AtomicSequence. In most cases the typed value will either be a single atomic value or an empty sequence; a single atomic value will be represented using class AtomicValue (which implements AtomicSequence) or one of its subclasses such as StringValue. An empty sequence is best recognized by calling atomicSequence.getLength() == 0.

getParent()

Gets the NodeInfo representing the parent element.

iterateAxis()

Returns an AxisIterator object that can be used to iterate over the nodes on any of the XPath axes. The first argument is an integer identifying the axis; the second is a NodeTest (a simple form of pattern) which can be used to filter the nodes on the axis. Supply null if you want all the nodes on the axis.

For other methods, see the NodeInfo JavaDoc documentation.

It is possible (though not easy) to provide your own implementation of the NodeInfo interface, perhaps allowing Saxon queries to run directly against some non-XML data source. There are helper methods in the Navigator class that reduce the amount of code you need to write to achieve this. See the implementations that map NodeInfo to DOM, DOM4J, JDOM or XOM to see how it is done.