Next page Previous page Start of chapter End of chapter

Validity

An XML document is said to be valid if it adheres to the definitions of the associated DTD. As a general rule, web browsers do not validate documents but only check them for well-formedness. If you are developing an application, you can use the parser's API to validate the document. If you are writing documents at hand, you can either use an online validator or download and run a local program.

An example of online validator is the XML Validation Form of the Brown University Scholarly Technology Group. A command line XML parser and validator is xmllint, which is part of the XML library libxml developed for the Gnome project (but usable outside of the Gnome platform). For instance, you can validate Turing.xml against Turing.dtd with the following syntax:

xmllint --dtdvalid Turing.dtd Turing.xml

If Turing.xml contains the document type declaration, you can use the following syntax:

xmllint --valid Turing.xml

Use the option --noout to avoid the output of the XML document.

You may also validate a document against a DTD using BaseX function validate:dtd as in the following example:

let $doc := doc('banking.xml')
let $schema := 'banking.dtd'
return validate:dtd($doc, $schema)
Next page Previous page Start of chapter End of chapter
Caffè XML - Massimo Franceschet