Changes

Jump to navigation Jump to search
702 bytes removed ,  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'''
* {{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'''
{| 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'''
|
* <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>
|}
{| 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}}. The supported {{Code|$featuresoptions}} are:
* {{Code|cache}}: Generated schemas are cached and reused.
* All other options are handled as features are assigned and passed on to the XSLT processorvalidator.
|- valign="top"
| '''Errors'''
|
* 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:get('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}} and returns warnings, errors and fatal errors in a string sequence. See {{Function||validate:xsd}} for more information of the {{Code|$featuresoptions}} parameter.
|- valign="top"
| '''Errors'''
{| 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}} and returns warnings, errors and fatal errors as XML. See {{Function||validate:xsd}} for more information of the {{Code|$featuresoptions}} parameter.
|- valign="top"
| '''Errors'''
{| width='100%'
|- valign="top"
| width='120' | '''SignaturesSignature'''|{{Func|<pre>validate:xsd-processor||() as xs:string}}</pre>
|- valign="top"
| '''Summary'''
{| width='100%'
|- valign="top"
| width='120' | '''SignaturesSignature'''|{{Func|<pre>validate:xsd-version||() as xs:string}}</pre>
|- valign="top"
| '''Summary'''
{| 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'''
{| 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'''
{| 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'''
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=
Bureaucrats, editor, reviewer, Administrators
13,554

edits

Navigation menu