<?xml version="1.0" encoding="iso-8859-1"?>
<?xml-stylesheet href="../make-menu.xsl" type="text/xsl"?><html>
   <head>
      <this-is section="sourcedocs" page="validation" subpage=""/>
      <!--
           Generated at 2010-10-29T18:20:48.427+01:00--><title>Saxonica: XSLT and XQuery Processing: Validation of Source Documents</title>
      <meta name="coverage" content="Worldwide"/>
      <meta name="copyright" content="Copyright Saxonica Ltd"/>
      <meta name="title"
            content="Saxonica: XSLT and XQuery Processing: Validation of Source Documents"/>
      <meta name="robots" content="noindex,nofollow"/>
      <link rel="stylesheet" href="../saxondocs.css" type="text/css"/>
   </head>
   <body class="main">
      <h1>Validation of Source Documents</h1>
      <p>With Saxon-EE, source documents may be validated against a schema. Not only does this perform a check
that the document is valid, it also adds type information to each element and attribute node in the document to
identify the schema type against which it was validated. It may also expand the source document by adding
default values of elements and attributes.</p>
      <p>If the option <code>-val:strict</code> is specified on the command line for <code>com.saxonica.Query</code>
or <code>com.saxonica.Transform</code>, then the principal source document to the query or transformation
is schema-validated, as is every document loaded using the <code>doc()</code> or <code>document()</code>
function. Saxon will look among all the loaded schemas for an element declaration that matches the outermost
element of the document, and will then check that the document is valid against that element declaration, reporting
a fatal error if it is not. The loaded schemas include schemas imported statically into the query or stylesheet
using <code>import schema</code> or <code>xsl:import-schema</code>, schemas referenced in the
<code>xsi:schemaLocation</code> or <code>xsi:noNamespaceSchemaLocation</code> attributes of the source
document itself, and schemas loaded by the application using the <code>addSchema</code> method of the
<a class="bodylink" href="../javadoc/net/sf/saxon/Configuration.html"><code>Configuration</code></a> object.</p>
      <p>As an alternative to <code>-val:strict</code>, the option <code>-val:lax</code> may be specified. This validates
the document if and only if an element declaration can be found. If there is no declaration of the outermost
element in any loaded schema, then it is left as an untyped document.</p>
      <p>When invoking transformations or queries from the Java API, the equivalent of the <code>-val:strict</code> option
is to call the method <code>setSchemaValidation(Validation.STRICT)</code> on the <a class="bodylink" href="../javadoc/net/sf/saxon/Configuration.html"><code>Configuration</code></a>
object. The equivalent of <code>-val:lax</code> is <code>setSchemaValidation(Validation.LAX)</code>.</p>
      <p>When documents are built using the <a class="bodylink" href="../javadoc/net/sf/saxon/s9api/DocumentBuilder.html"><code>DocumentBuilder</code></a> in the s9api interface, or in the Saxon.Api
interface on .NET, validation may be controlled by setting the appropriate options on the <code>DocumentBuilder</code>.</p>
      <p>On Java interfaces that expect a JAXP <code>Source</code> object it is possible to request validation by supplying
an <a class="bodylink" href="../javadoc/net/sf/saxon/lib/AugmentedSource.html"><code>AugmentedSource</code></a>. This consists of a <code>Source</code> and a set of options, including
validation options; since <code>AugmentedSource</code> implements the JAXP <code>Source</code> interface
it is possible to use it anywhere that a <code>Source</code> is expected, including as the object returned by
a user-written <code>URIResolver</code>.</p>
      <p>Saxon's standard <code>URIResolver</code> uses this technique if it has been enabled 
(for example by using <code>-p</code> on the command line). With this option,
any URI containing the query parameter <code>?val=strict</code> (for example, <code>doc('source.xml?val=strict')</code>)
causes strict validation to be requested
for that document, while <code>?val=lax</code> requests lax validation, 
and <code>?val=strip</code> requests no validation.</p>
      <table width="100%">
         <tr>
            <td>
               <p align="right"><a class="nav" href="whitespace.xml">Next</a></p>
            </td>
         </tr>
      </table>
   </body>
</html>