xmllint: A validator for XML files
The xmllint program validates an XML file against its DTD (Document Type Definition) and reports on any differences. For a full list of options, see the man page for xmllint.
The XML file should have a valid <!DOCTYPE...> declaration that refers to the DTD. To run the program on a Linux system at the TCC, type:
xmllint --valid --noout file.xml
For example, suppose you want to check whether file granite.xml is valid according to a DTD contained in file rocks.dtd in the same directory, and suppose the root element of that document type is <mineral>. You'd need a DOCTYPE declaration like this:
<!DOCTYPE mineral SYSTEM "rocks.dtd">
To validate this file you'd use this command:
xmllint --noout --valid granite.xml
If your XML file does not use a DOCTYPE declaration, you can still validate it against a specific DTD schema. Use this form:
xmllint --noout --dtdvalid URL file.xmlwhere URL is the URL of the DTD schema.
Relax NG is a more modern, improved schema language. Relax NG schemas can be expressed in either of two formats: RNG, an XML-based schema whose name ends in .rng; or RNC, a “compact format” file whose name ends in .rnc.
To validate a file against a schema in Relax NG format:
xmllint --noout --relaxng schema.rng file.xml
If your schema is in Compact Format, you can use the trang program to convert it to RNG format:
trang file.rnc file.rng
For example, suppose your schema is airport.rnc, and you have an XML file named sfo.xml to validate against it. This command would translate the schema to RNG format:
trang airport.rnc airport.rngand this command would validate the file:
xmllint --noout --relaxng airport.rng sfo.xml
If your schema file is in XSchema, use a command of this form:
xmllint --noout --schema schema.xsd file.xml
John Shipman, email@example.com
Last updated: 2007/06/07 01:18:01 UT