Changes

Jump to navigation Jump to search
2,383 bytes added ,  16:12, 5 June 2015
no edit summary
This [[Module Library|XQuery Module]] contains functions to perform validations against [http://en.wikipedia.org/wiki/Document_Type_Declaration DTDs], [http://www.w3.org/XML/Schema XML Schema] and (since {{Version|8.3}}) [http://en.wikipediarelaxng.org/wiki/Document_Type_Declaration Document Type DeclarationsRelaxNG]. By default: * For DTDs and XML Schema, this module uses Java’s standard validatorsis used. As an alternative* For XML Schema, the [http://www.saxonica.com/ Saxon XSLT Processor] is used if ({{Code|saxon9heit is added to the classpath.jar}}* For RelaxNG, {{Code|saxon9pe[http://www.thaiopensource.jar}} or {{Code|saxon9eecom/relaxng/jing.jar}}) is html Jing] must be added to the classpath. Jing is included in the full distributions of BaseX.
=Conventions=
=Functions=
 
==validate:dtd==
{| width='100%'
|-
| width='120' | '''Signatures'''
|{{Func|validate:dtd|$input as item()|empty-sequence()}}<br />{{Func|validate:dtd|$input as item(), $dtd as xs:string|empty-sequence()}}
|-
| '''Summary'''
|Validates the document specified by {{Code|$input}}. {{Code|$input}} can be specified as:
* an {{Code|xs:string}}, containing the path to the resource,
* an {{Code|xs:string}}, containing the resource in its string representation, or
* a {{Code|node()}}, containing the resource itself.
{{Code|$schema}} can be used to specify the DTD for validation. If no DTD is given, {{Code|$input}} is required to contain a DTD doctype declaration.<br />
|-
| '''Errors'''
|{{Error|BXVA0001|#Errors}} the validation fails.<br/>{{Error|BXVA0002|#Errors}} the validation process cannot be started.
|-
| '''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 class="brush:xquery">
try {
let $doc := <invalid/>
let $dtd := '<!ELEMENT root (#PCDATA)>'
return validate:dtd($doc, $dtd)
} catch BXVA0001 {
'DTD Validation failed.'
}
</pre>
|-
|}
 
==validate:dtd-info==
 
{| width='100%'
|-
| width='120' | '''Signatures'''
|{{Func|validate:dtd-info|$input as item()|xs:string*}}<br />{{Func|validate:dtd-info|$input as item(), $dtd as xs:string|xs:string*}}
|-
| '''Summary'''
|Validates the document specified by {{Code|$input}} and returns warning, errors and fatal errors in a string sequence. {{Code|$input}} can be specified as:
* {{Code|xs:string}}, containing the path to the resource,
* {{Code|xs:string}}, containing the resource in its string representation, or
* {{Code|node()}}, containing the resource itself.
{{Code|$schema}} can be used to specify the DTD for validation. If no DTD is given, {{Code|$input}} is required to contain a DTD doctype declaration.<br />
|-
| '''Errors'''
|{{Error|BXVA0002|#Errors}} the validation process cannot be started.
|}
==validate:xsd==
 
{| width='100%'
|-
|}
==validate:dtdrng== {{Mark|Introduced with Version 8.3}}: 
{| width='100%'
|-
| width='120' | '''Signatures'''
|{{Func|validate:dtdrng|$input as item(), $schema as item()|empty-sequence()}}<br />{{Func|validate:dtdrng|$input as item(), $dtd schema as item(), $compact as xs:stringboolean|empty-sequence()}}
|-
| '''Summary'''
|Validates the document specified by {{Code|$input}}. The validation schema is specified by {{Code|$schema}}, and {{Code|$compact}} indicates if the schema uses the compact RelaxNG notation. Both {{Code|$input}} and {{Code|$schema}} can be specified as:* an {{Code|xs:string}}, containing the path to the resource,* an {{Code|xs:string}}, containing the resource in its string representation, or* a {{Code|node()}}, containing the resource itself.{{Code|$schema}} can be used to specify the DTD for validation. If no DTD is given, {{Code|$input}} is required to contain a DTD doctype declaration.<br />
|-
| '''Errors'''
|{{Error|BXVA0001|#Errors}} the validation fails.<br/>{{Error|BXVA0002|#Errors}} the validation process cannot be started.<br/>{{Error|BXVA0003|#Errors}} the RelaxNG validator is not available.
|-
| '''Examples'''
|
* {{Code|validate:dtdrng('doc.xml', 'doc.dtdrng')}} validates the document {{Code|doc.xml}} against the specified DTD file schema {{Code|docrng.dtdxsd}}.* The following example validates an invalid document against a DTD, which is specified as string:<pre class="brush:xquery">try { let $doc := <invalid/> let $dtd := '<!ELEMENT root (#PCDATA)>' return validate:dtd($doc, $dtd)} catch BXVA0001 { 'DTD Validation failed.'}</pre>|-
|}
==validate:dtdrng-info== {{Mark|Introduced with Version 8.3}}:
{| width='100%'
|-
| width='120' | '''Signatures'''
|{{Func|validate:dtdrng-info|$input as item(), $schema as item()|xs:string*}}<br />{{Func|validate:dtdrng-info|$input as item(), $dtd schema as item(), $compact as xs:stringboolean|xs:string*}}
|-
| '''Summary'''
|Validates the document specified by {{Code|$input}} and returns warningwarnings, errors and fatal errors in a string sequence. The validation schema is specified by {{Code|$schema}}, and {{Code|$compact}} indicates if the schema uses the compact RelaxNG notation. {{Code|$input}} and {{Code|$schema}} can be specified as:
* {{Code|xs:string}}, containing the path to the resource,
* {{Code|xs:string}}, containing the resource in its string representation, or
* {{Code|node()}}, containing the resource itself.
{{Code|$schema}} can be used to specify the DTD for validation. If no DTD is given, {{Code|$input}} is required to contain a DTD doctype declaration.<br />
|-
| '''Errors'''
|{{Error|BXVA0002|#Errors}} the validation process cannot be started.<br/>{{Error|BXVA0003|#Errors}} the RelaxNG validator is not available.
|}
|{{Code|BXVA0002}}
|The validation cannot be started.
|-
|{{Code|BXVA0003}}
|No RelaxNG validator is available.
|}
=Changelog=
 
;Version 8.3
* Added: [[#validate:rng|validate:rng]], [[#validate:rng-info|validate:rng-info]]
;Version 7.6
Bureaucrats, editor, reviewer, Administrators
12,953

edits

Navigation menu