<?xml version="1.0" encoding="iso-8859-1"?>
<?xml-stylesheet href="../../make-menu.xsl" type="text/xsl"?><html>
   <head>
      <this-is section="xpath-api" page="jaxp-xpath" subpage="return-types"/>
      <!--
           Generated at 2011-12-09T20:47:22.916Z--><title>Saxonica: XSLT and XQuery Processing: Return types</title>
      <meta name="coverage" content="Worldwide"/>
      <meta name="copyright" content="Copyright Saxonica Ltd"/>
      <meta name="title" content="Saxonica: XSLT and XQuery Processing: Return types"/>
      <meta name="robots" content="noindex,nofollow"/>
      <link rel="stylesheet" href="../../saxondocs.css" type="text/css"/>
   </head>
   <body class="main">
      <h1>Return types</h1>
      <p>The JAXP specification leaves it rather up to the implementation how the results of an XPath expression will
be returned. This is partly because it is defined only for XPath 1.0, which has a much simpler type system, and
partly because it is deliberately designed to be independent of the object model used to represent XML trees.</p>
      <p>If you specify the return type <code>XPathConstants.BOOLEAN</code> then Saxon will return the effective
boolean value of the expression, as a <code>java.lang.Boolean</code>. This is the same as wrapping the expression
in a call of the XPath <code>boolean()</code> function.</p>
      <p>If you specify the return type <code>XPathConstants.STRING</code> then Saxon will return the result
of the expression converted to a string, as a <code>java.lang.String</code>. 
This is the same as wrapping the expression in a call of the XPath <code>string()</code> function.</p>
      <p>If you specify the return type <code>XPathConstants.NUMBER</code> then Saxon will return the result
of the expression converted to a double as a <code>java.lang.Double</code>. 
This is the same as wrapping the expression in a call of the XPath <code>number()</code> function.</p>
      <p>If you specify the return type <code>XPathConstants.NODE</code> then Saxon will return the result
the result as a node object in the selected object model. With the DOM model this will be an instance
of <code>org.w3.dom.Node</code>, with the native Saxon model it will be an instance of <code>net.sf.saxon.om.NodeInfo</code>,
and so on.</p>
      <p>If the return type is <code>XPathConstants.NODESET</code>, the result will in general be a Java <code>List</code>
containing node objects in the selected object model. It may also contain non-node objects if that's
what the XPath expression returned. As a special case, if the supplied context node is a DOM node, 
and if the results are all DOM nodes, then they will be returned in the form of a
DOM <code>NodeList</code> object.</p>
      <p>Saxon does not recognize additional values for the return type other than the values defined in JAXP. If you
want to return a different result type, for example a list of integers or a date, then it is probably best not to use this API;
if you must, however, then use one of the methods in which the result
type is unspecified. If any conversions are necessary, do them within the XPath expression itself, using casts
or constructor functions. The Java object that is returned will be a representation of the XPath value, 
converted in the same way as arguments to a extension functions.</p>
      <table width="100%">
         <tr>
            <td>
               <p align="right"><a class="nav" href="saxon-additions.xml">Next</a></p>
            </td>
         </tr>
      </table>
   </body>
</html>