Representation of XDM values

Values returned by XPath expressions in the s9api interface are represented as instances of the class net.sf.saxon.s9api.XdmValue. The XdmValue class is also used to supply parameters to stylesheets and transformations, and to return the results of XSLT or XQuery evaluation.

The subclasses of XdmValue directly reflect the XDM model:

XdmValue (any sequence) XdmItem (any single item, that is, a sequence of length one) XdmNode (any node) XdmAtomicValue (any atomic value) XdmFunctionItem (a function item) XdmMap (a map) XdmArray (an array) XdmExternalObject (an item that encapsulates a Java or .NET object) XdmEmptySequence (a sequence containing no items)

These objects are generally immutable.

A variety of methods are provided to convert between these classes and "ordinary" Java equivalents. For example an XdmAtomicValue can be constructed directly from a Java boolean, String, long, BigDecimal, or Instant (inter alia), and methods such as getBooleanValue() and getStringValue() are available to convert in the other direction.

As an alternative to use of XPath, the select() method on XdmValue provides powerful navigation capability around XDM trees. The select() method takes as argument a Step (which is a function from one node to related nodes) and returns an XdmStream of nodes as a result. There is a library (Steps) of Step functions corresponding to all the XPath axes, and the results of applying a Step can be filtered using predicates: there is also a library (Predicates) of commonly-used Predicates.

For example, if root is a document node, then root.select(descendant("p")).asXdmValue() selects all the descendant elements with local name "p" in the form of an XdmValue.

The XdmNode class in this hierarchy is implemented as a wrapper around the lower-level NodeInfo interface which provides more detailed access to information associated with nodes. The NodeInfo interface is designed primarily for internal use within Saxon, whereas XdmNode is designed for application use.