<?xml version="1.0" encoding="iso-8859-1"?>
<?xml-stylesheet href="../make-menu.xsl" type="text/xsl"?><html>
   <head>
      <this-is section="schema-processing" page="saqueryapi" subpage=""/>
      <!--
           Generated at 2010-10-29T18:20:48.427+01:00--><title>Saxonica: XSLT and XQuery Processing: Schema-Aware XQuery from Java</title>
      <meta name="coverage" content="Worldwide"/>
      <meta name="copyright" content="Copyright Saxonica Ltd"/>
      <meta name="title"
            content="Saxonica: XSLT and XQuery Processing: Schema-Aware XQuery from Java"/>
      <meta name="robots" content="noindex,nofollow"/>
      <link rel="stylesheet" href="../saxondocs.css" type="text/css"/>
   </head>
   <body class="main">
      <h1>Schema-Aware XQuery from Java</h1>
      <p>When queries are controlled using the Java API, the equivalent to the <code>-val</code>
option is to create a <a class="bodylink"
            href="../javadoc/com/saxonica/config/EnterpriseConfiguration.html"><code>EnterpriseConfiguration</code></a> instead of a <code>Configuration</code> object, 
and then to call <code>setSchemaValidationMode(net.sf.saxon.lib.Validation.STRICT)</code> on this object.
The value <a class="bodylink" href="../javadoc/net/sf/saxon/lib/Validation.html#LAX"><code>Validation.LAX</code></a> can also be used.</p>
      <p>This option switches validation on for all source documents used by any transformation under the control of this
<code>EnterpriseConfiguration</code>. If you want finer control, so that some documents are validated and others are not, you can
achieve this by using the <a class="bodylink" href="../javadoc/net/sf/saxon/lib/AugmentedSource.html"><code>AugmentedSource</code></a> object. An <code>AugmentedSource</code> is a wrapper around
a normal JAXP <code>Source</code> object, in which additional properties can be set: for example, a property to
request validation of the document. The <code>AugmentedSource</code> itself implements the JAXP <code>Source</code>
interface, so it can be used anywhere that an ordinary <code>Source</code> object can be used, for example as the
first argument to the <code>buildDocument()</code> method of the <code>QueryProcessor</code>, and as the return value from
a user-written <code>URIResolver</code>.</p>
      <p>If the <a class="bodylink" href="../javadoc/com/saxonica/ptree/PTreeURIResolver.html"><code>PTreeURIResolver</code></a> is used, it is also possible to control validation for each source document
by means of query parameters in the document URI. For example, <code>doc('source.xml?val=strict')</code> requests
the loading of the file <code>source.xml</code> with strict validation.</p>
      <p>The <a class="bodylink" href="../javadoc/net/sf/saxon/Configuration.html"><code>Configuration</code></a> method <code>setValidationWarnings()</code> 
has the same effect as the <code>-vw</code>
option on the command line: validation errors encountered when processing the final result tree are
reported to the <code>ErrorListener</code> as warnings, not as fatal errors. They are also reported
as XML comments in the result tree.</p>
      <p>Schemas can be loaded using either of the techniques used with the command-line interface: that is, by specifying
them in the <code>import schema</code> directive in the query prolog, or by including them in an <code>xsi:schemaLocation</code>
attribute in a source document. In addition, they can be loaded using the <code>addSchemaSource()</code> method on the
<code>EnterpriseConfiguration</code> class.</p>
      <p>All schemas that are loaded are cached as part of the <a class="bodylink"
            href="../javadoc/com/saxonica/config/EnterpriseConfiguration.html"><code>EnterpriseConfiguration</code></a>. This is true whether the
schema is loaded explicitly using the Java API, whether it is loaded as a result of <code>import schema</code> in a query,
or whether it is referenced in an <code>xsi:schemaLocation</code> attribute in a source document. There can only
be one schema document loaded for each namespace: any further attempts to load a schema for a given target namespace
will return the existing loaded schema, rather than loading a new one. Note in particular that this means there
can only be one loaded no-namespace schema document. If you want to force loading of a different schema document
for an existing namespace, the only way to do it is to create a new <code>EnterpriseConfiguration</code>.</p>
      <table width="100%">
         <tr>
            <td>
               <p align="right"><a class="nav" href="schema11.xml">Next</a></p>
            </td>
         </tr>
      </table>
   </body>
</html>