Changes

Jump to navigation Jump to search
191 bytes added ,  18:38, 1 December 2023
m
Text replacement - "syntaxhighlight" to "pre"
{| width='100%'
|-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:
<syntaxhighlight pre lang="'xquery"'>
try {
let $doc := <invalid/>
'DTD Validation failed.'
}
</syntaxhighlightpre>
|}
{| 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%'
|-valign="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.
|-valign="top"
| '''Examples'''
|
* <code>validate:dtd-report(<invalid/>, '<!ELEMENT root (#PCDATA)>')</code> returns:
<syntaxhighlight pre lang="xml">
<report>
<status>invalid</status>
<message level="Error" line="2" column="11">Element type "invalid" must be declared.</message>
</report>
</syntaxhighlightpre>
|}
==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:
<syntaxhighlight pre lang="'xquery"'>
let $doc := <simple:root xmlns:simple='http://basex.org/simple'/>
let $schema :=
</xs:schema>
return validate:xsd($doc, $schema)
</syntaxhighlightpre>
* Validate all documents of a database against the specified schema, using the supplied feature:
<syntaxhighlight pre lang="'xquery"'>for $city in db:openget('cities')
return validate:xsd($city, 'city.xsd',
map { 'http://javax.xml.XMLConstants/feature/secure-processing': true() }
)
</syntaxhighlightpre>
|}
{| width='100%'
|-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.
{| 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.
{| 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.
{| 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.
If you want to use Schematron for validating documents, install Vincent Lizzi’s excellent [https://github.com/Schematron/schematron-basex Schematron XQuery Module for BaseX]:
<syntaxhighlight pre lang="'xquery"'>
repo:install('https://github.com/Schematron/schematron-basex/raw/master/dist/schematron-basex-1.2.xar')
</syntaxhighlightpre>
The following query illustrates how documents are validated. It is directly taken from the GitHub project:
<syntaxhighlight pre lang="'xquery"'>
import module namespace schematron = "http://github.com/Schematron/schematron-basex";
return concat(schematron:message-level($message), ': ', schematron:message-description($message))
)
</syntaxhighlightpre>
=Errors=
! width="110"|Code
|Description
|-valign="top"
|{{Code|error}}
|The document cannot be validated against the specified schema.
|-valign="top"
|{{Code|init}}
|The validation cannot be started.
|-valign="top"
|{{Code|not-found}}
|No validator is available.
=Changelog=
 
;Version 11.0
 
* Updated: {{Function||validate:xsd}}, {{Function||validate:xsd-info}}, {{Function||validate:xsd-report}}: caching feature added
;Version 9.2
* Added: {{Function||validate:rng}}, {{Function||validate:rng-info}}
* Added: [[#{{Function||validate:dtd-report|dtd-report]]}}, [[#{{Function||validate:xsd-report|xsd-report]]}}, {{Function||validate:rng-report}}
;Version 7.6
Bureaucrats, editor, reviewer, Administrators
13,554

edits

Navigation menu