Next / Previous / Index / ITC Help System / Publications / Site map / NM Tech homepage

xmllint: A validator for XML files

Tech Computer Center logo

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.

Validating using the DOCTYPE

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

Validating against a specific DTD

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.xml
where URL is the URL of the DTD schema.

Validating against a Relax NG 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.rng
and this command would validate the file:
    xmllint --noout --relaxng airport.rng sfo.xml

Validating against XSchema

If your schema file is in XSchema, use a command of this form:

    xmllint --noout --schema schema.xsd file.xml

See also: XML and SGML standards and useful links
Site map
Index: Keyword index to help pages
Help: New Mexico Tech Information Technology and Communications: Help System
ITC Publications
To report a problem: File a ticket
Send mail to the User consultant on duty or call them at 575-835-5437
Home: About New Mexico Tech

John Shipman,
Last updated: 2007/06/07 01:18:01 UT
QR two-dimensional bar code