|-valign="top"| width='120' | '''SignaturesSignature'''|{{Func|validate:dtd|$input as item()|empty-sequence()}}<br /pre>{{Func|validate:dtd|( $input as item(), $schema as xs:string?| := ()) as empty-sequence()}}</pre>|-valign="top"
| '''Summary'''
|Validates the XML {{Code|$input}} document against a {{Code|$schema}} and returns an empty sequence or an error.
|-valign="top"
| '''Errors'''
|{{Error|error|#Errors}} the validation fails.<br/>{{Error|init|#Errors}} the validation process cannot be started.<br/>{{Error|not-found|#Errors}} no DTD validator is available.
|-valign="top"
| '''Examples'''
|
* {{Code|validate:dtd('doc.xml', 'doc.dtd')}} validates the document {{Code|doc.xml}} against the specified DTD file {{Code|doc.dtd}}.
* The following example validates an invalid document against a DTD, which is specified as string:
<pre classlang="brush:'xquery"'>
try {
let $doc := <invalid/>
{| width='100%'
|-valign="top"| width='120' | '''SignaturesSignature'''|{{Func|validate:dtd-info|$input as item()|xs:string*}}<br /pre>{{Func|validate:dtd-info|( $input as item(), $schema as xs:string?| := ()) as xs:string*}}</pre>|-valign="top"
| '''Summary'''
|Validates the XML {{Code|$input}} document against a {{Code|$schema}} and returns warnings, errors and fatal errors in a string sequence.
|-valign="top"
| '''Errors'''
|{{Error|init|#Errors}} the validation process cannot be started.<br/>{{Error|not-found|#Errors}} no DTD validator is available.
|-valign="top"
| '''Examples'''
|
{| width='100%'
| width- valign='100%'|-"top"| width='120' | '''SignaturesSignature'''|{{Func|validate:dtd-report|$input as item()|element(report)}}<br /pre>{{Func|validate:dtd-report|( $input as item(), $schema as xs:string?| := ()) as element(report)}}</pre>|-valign="top"
| '''Summary'''
|Validates the XML {{Code|$input}} document against a {{Code|$schema}} and returns warnings, errors and fatal errors as XML.
|-valign="top"
| '''Errors'''
|{{Error|init|#Errors}} the validation process cannot be started.<br/>{{Error|not-found|#Errors}} no DTD validator is available.
{{Mark|Updated with Version 9.2:}} Version argument was dropped (the latest version will always be used).
Checks whether an XML document validates against an XML Schema. The input document and the schema can be specified as:
* {{Code|node()}}, containing the resource itself.
If no schema is given, the input is expected to contain an {{Code|xsi:(noNamespace)schemaLocation}} attribute, as defined in [httphttps://www.w3.org/TR/xmlschema-1/#xsi_schemaLocation W3C XML Schema].
Different XML Schema processors are supported:
* By default, the '''Java implementation''' of XML Schema 1.0 is used (it is based on an old version of Apache Xerces).
* The latest version of '''Xerces2''' provides implementations of XML Schema 1.0 and 1.1. The processor will be applied if you download one of the [httphttps://xerces.apache.org/mirrors.cgi#binary binary distributions] and copy the following libraries to the {{Code|lib/custom}} directory of the full distribution of BaseX:
* '''Saxon Enterprise Edition''' will be applied used if you download the [https://www.saxonica.com/download/java.xml ZIP release] and if you copy {{Code|saxon9ee.jar}} and a valid license key to the classpath.
==validate:xsd==
{{Announce|Updated with Version 11:}} caching feature added.
{| width='100%'
|-valign="top"| width='120' | '''SignaturesSignature'''|{{Func|validate:xsd|$input as item()|empty-sequence()}}<br /pre>{{Func|validate:xsd|( $input as item(), $schema as item()?|empty-sequence()}}<br />{{Func|validate :xsd|$input as item= (), $schema options as itemmap(*)?, $features as := map(*{ })|as empty-sequence()}}</pre>|-valign="top"
| '''Summary'''
|Validates the XML {{Code|$input}} document against a {{Code|$schema}}, using the processor-specific . The supported {{Code|$featuresoptions}} are:* {{Code|cache}}: Generated schemas are cached and reused.* All other options are handled as features and passed on to the validator.|-valign="top"
| '''Errors'''
|{{Error|error|#Errors}} the validation fails.<br/>{{Error|init|#Errors}} the validation process cannot be started.<br/>{{Error|not-found|#Errors}} no XML Schema validator is available.
|-valign="top"
| '''Examples'''
|
* Pass on document and schema as nodes:
<pre classlang="brush:'xquery"'>
let $doc := <simple:root xmlns:simple='http://basex.org/simple'/>
let $schema :=
</pre>
* Validate all documents of a database against the specified schema, using the supplied feature:
<pre classlang="brush:'xquery"'>for $city in db:openget('cities')
|-valign="top"| width='120' | '''SignaturesSignature'''|{{Func|validate:xsd-info|$input as item()|xs:string*}}<br /pre>{{Func|validate:xsd-info|( $input as item(), $schema as item()?|xs :string*}}<br />{{Func|validate:xsd-info|$input as item= (), $schema options as itemmap(*)?, $features as := map(*{ })|as xs:string*}}</pre>|-valign="top"
| '''Summary'''
|Validates the XML {{Code|$input}} document against a {{Code|$schema}}, using the processor-specific {{Code|$features}}, and returns warnings, errors and fatal errors in a string sequence. See {{Function||validate:xsd}} for more information of the {{Code|$options}} parameter.|-valign="top"
| '''Errors'''
|{{Error|init|#Errors}} the validation process cannot be started.<br/>{{Error|not-found|#Errors}} no XML Schema validator is available.
{| width='100%'
|-valign="top"| width='120' | '''SignaturesSignature'''|{{Func|validate:xsd-report|$input as item()|element(report)}}<br /pre>{{Func|validate:xsd-report|( $input as item(), $schema as xs:string?|element(report)}}<br />{{Func|validate :xsd-report|$input as item= (), $schema as xs:string?, $features options as map(*)| := map { }) as element(report)}}</pre>|-valign="top"
| '''Summary'''
|Validates the XML {{Code|$input}} document against a {{Code|$schema}}, using the processor-specific {{Code|$features}}, and returns warnings, errors and fatal errors as XML. See {{Function||validate:xsd}} for more information of the {{Code|$options}} parameter.|-valign="top"
| '''Errors'''
|{{Error|init|#Errors}} the validation process cannot be started.<br/>{{Error|not-found|#Errors}} no XML Schema validator is available.
==validate:xsd-processor==
{{Mark|Introduced with Version 9.2:}}
{| width='100%'
|-valign="top"| width='120' | '''SignaturesSignature'''|{{Func|<pre>validate:xsd-processor||() as xs:string}}</pre>|-valign="top"
| '''Summary'''
|Returns the name of the applied XSD processor.
==validate:xsd-version==
{{Mark|Introduced with Version 9.2:}}
{| width='100%'
|-valign="top"| width='120' | '''SignaturesSignature'''|{{Func|<pre>validate:xsd-version||() as xs:string}}</pre>|-valign="top"
| '''Summary'''
|Returns the supported version of XSD Schema.
* {{Code|node()}}, containing the resource itself.
RelaxNG validation will be available if [httphttps://wwwrelaxng.thaiopensource.comorg/relaxngjclark/jing.html Jing] exists in the classpath. The latest version, {{Code|jing-20091111.jar}}, is included in the full distributions of BaseX. As Jing additionally supports [http://www.nvdl.org/ NVDL] validation, you can also use the functions to validate the input against NVDL schemas.
==validate:rng==
{| width='100%'
|-valign="top"| width='120' | '''SignaturesSignature'''|{{Func|validate:rng|$input as item(), $schema as item()|empty-sequence()}}<br/pre>{{Func|validate:rng|( $input as item(), $schema as item(), $compact as xs:boolean|? := map { }) as empty-sequence()}}</pre>|-valign="top"
| '''Summary'''
|Validates the XML {{Code|$input}} document against a {{Code|$schema}}, using the XML or {{Code|$compact}} notation.
|-valign="top"
| '''Errors'''
|{{Error|error|#Errors}} the validation fails.<br/>{{Error|init|#Errors}} the validation process cannot be started.<br/>{{Error|not-found|#Errors}} the RelaxNG validator is not available.
|-valign="top"
| '''Examples'''
|
{| width='100%'
|-valign="top"| width='120' | '''SignaturesSignature'''|{{Func|validate:rng-info|$input as item(), $schema as item()|xs:string*}}<br/pre>{{Func|validate:rng-info|( $input as item(), $schema as item(), $compact as xs:boolean|? := map { }) as xs:string*}}</pre>|-valign="top"
| '''Summary'''
|Validates the XML {{Code|$input}} document against a {{Code|$schema}}, using the XML or {{Code|$compact}} notation, and returns warnings, errors and fatal errors in a string sequence.
|-valign="top"
| '''Errors'''
|{{Error|init|#Errors}} the validation process cannot be started.<br/>{{Error|not-found|#Errors}} the RelaxNG validator is not available.
{| width='100%'
|-valign="top"| width='120' | '''SignaturesSignature'''|{{Func|validate:rng-report|$input as item(), $schema as xs:string|element(report)}}<br /pre>{{Func|validate:rng-report|( $input as item(), $schema as xs:string, $compact as xs:boolean|? := map { }) as element(report)}}</pre>|-valign="top"
| '''Summary'''
|Validates the XML {{Code|$input}} document against a {{Code|$schema}}, using the XML or {{Code|$compact}} notation, and returns warnings, errors and fatal errors as XML.
|-valign="top"
| '''Errors'''
|{{Error|init|#Errors}} the validation process cannot be started.<br/>{{Error|not-found|#Errors}} The RelaxNG validator is not available.
=Schematron Validation=
If you want to use Schematron for validating documents, simply install Vincent Lizzi’s excellent [https://github.com/Schematron/schematron-basex Schematron XQuery Module for BaseX]:
* Added: [[#validate:xsd-processor{{Function||validate:xsd-processor]]}}, [[#validate:xsd-version{{Function||validate:xsd-version]]}}* Updated: [[#validate:xsd{{Function||validate:xsd]]}}, [[#validate:xsd-info{{Function||validate:xsd-info]]}}, [[#validate:xsd-report{{Function||validate:xsd-report]]}}: version argument was dropped (the latest version will always be used)