xml-validate
Validate XML files against a schema
TLDR
Validate one or more XML documents for well-formedness only
Validate one or more XML documents against a Document Type Definition (DTD)
Validate one or more XML documents against an XML Schema Definition (XSD)
Validate one or more XML documents against a Relax NG schema (RNG)
Display help
SYNOPSIS
xml-validate [options] file.xml
PARAMETERS
file.xml
The path to the XML file to be validated. This is typically the only required argument.
--dtdvalid URL
Validates the XML document against the DTD specified by the provided URL. This option is passed directly to xmllint.
--relaxng file
Validates the XML document against the RelaxNG schema specified by file. This option is passed directly to xmllint.
--schema file
Validates the XML document against the W3C XML Schema (XSD) specified by file. This option is passed directly to xmllint.
--noout
Suppresses output of the XML document itself, showing only errors. This is very common when only validation status is desired and is often implied or default for xml-validate wrappers.
--postvalid
Performs DTD validation after parsing. This option is passed directly to xmllint and often implies --valid.
--xinclude
Processes XInclude elements within the document before validation. This can be important if included content affects validity.
--nonet
Disables network access for fetching DTDs or schemas. Useful for validation against local files or in environments without internet access.
DESCRIPTION
The xml-validate command is a utility designed to check the well-formedness and validity of XML documents. Often, it acts as a convenient wrapper script for xmllint, specifically invoking it with options like --valid or others necessary for schema validation. Its primary purpose is to ensure that an XML file adheres to its Document Type Definition (DTD) or a specified XML schema (like XML Schema Definition (XSD) or RelaxNG).
When executed, xml-validate processes the input XML file and reports any parsing errors, well-formedness issues, or validation failures to standard error. A successful validation typically results in no output (unless configured otherwise) and an exit code of 0, making it ideal for use in automated scripts, CI/CD pipelines, or pre-commit hooks where XML compliance is critical. It simplifies the validation process by abstracting away the more verbose xmllint command arguments for common validation tasks.
CAVEATS
xml-validate is frequently a simple shell script wrapper around the more powerful xmllint command (part of the libxml2 library). As such, its exact behavior and available options can vary slightly depending on the distribution and how the wrapper script is implemented. It relies entirely on xmllint's capabilities, meaning it generally supports DTD, W3C XML Schema (XSD), and RelaxNG for validation, but may not support other schema languages like Schematron natively. Error messages are typically verbose, originating directly from xmllint's parsing and validation engine.
EXIT CODES
The command typically returns an exit code of 0 if the XML document is well-formed and valid according to the specified DTD or schema. A non-zero exit code (e.g., 1 or higher) indicates that the document is either not well-formed, invalid, or an error occurred during processing.
SCHEMA SUPPORT
xml-validate, through xmllint, natively supports validation against DTDs (Document Type Definitions), W3C XML Schemas (XSD), and RelaxNG schemas. The specific schema type is typically inferred or explicitly specified using options like --dtdvalid, --schema, or --relaxng.
HISTORY
The xml-validate command emerged as a user-friendly front-end to the validation capabilities of xmllint, which is the command-line interface for libxml2, a foundational XML toolkit developed by Daniel Veillard. Rather than being a standalone project, xml-validate is often distributed as part of libxml2-utils or similar packages in Linux distributions, providing a quick way to perform basic XML validation without delving into the broader set of xmllint options. Its development history is thus intertwined with the evolution of libxml2 itself, focusing on making common validation tasks more accessible.
SEE ALSO
xmllint(1), xmlstarlet(1), xsltproc(1)