LinuxCommandLibrary

xmllint

TLDR

Check if an XML file is well-formed

$ xmllint [file.xml]
copy
Format and pretty-print an XML file
$ xmllint --format [file.xml]
copy
Validate against a DTD
$ xmllint --valid [file.xml]
copy
Validate against an XSD schema
$ xmllint --schema [schema.xsd] [file.xml]
copy
Extract data using XPath
$ xmllint --xpath "[//element/@attribute]" [file.xml]
copy
Format in place (output to same file)
$ xmllint --format [file.xml] -o [file.xml]
copy
Remove blank nodes from output
$ xmllint --noblanks [file.xml]
copy

SYNOPSIS

xmllint [options] xmlfile...

DESCRIPTION

xmllint is a command-line XML parser and processor from the libxml2 library. It can parse XML files to check for well-formedness, validate documents against DTDs or schemas (XSD, RelaxNG), format XML for readability, and query documents using XPath expressions.
The tool is indispensable for working with XML data in shell scripts and automated workflows. It can detect syntax errors, validate against various schema types, extract specific data using XPath, and transform or clean up XML output.
Common uses include validating configuration files, extracting data from XML APIs, formatting machine-generated XML for human readability, and preprocessing XML before further transformation with XSLT.

PARAMETERS

--format

Reformat and reindent the output
--valid
Validate against the DTD declared in the document
--schema file
Validate against the specified XSD schema
--relaxng file
Validate against a RelaxNG schema
--dtdvalid file
Validate against the specified DTD
--xpath expression
Evaluate XPath expression and print results
--output file, -o file
Write output to specified file
--noout
Suppress normal output (useful with validation)
--noblanks
Remove ignorable blank nodes from output
--encode encoding
Output in specified encoding
--html
Parse input as HTML instead of XML
--recover
Try to recover from parsing errors
--nonet
Don't fetch external entities from network
--c14n
Canonicalize output (for digital signatures)
--shell
Enter interactive shell mode
--version
Display version information

CAVEATS

XPath support is limited to XPath 1.0; for XPath 2.0+ use tools like saxon. Large files may consume significant memory as the entire document is loaded. External entity expansion is enabled by default and can pose security risks with untrusted input; use --nonet and --noent flags for untrusted data. Some HTML parsing may require the --html --recover combination for malformed documents.

HISTORY

xmllint was developed as part of the libxml2 project, created by Daniel Veillard starting in 1998. The library and its tools became the standard XML processing toolkit on Unix-like systems, used by projects like GNOME, PHP, and countless others. It is installed by default on most Linux distributions and macOS. The tool has been continuously maintained and updated to support evolving XML standards.

SEE ALSO

xsltproc(1), xmlstarlet(1), jq(1), yq(1), xq(1)

> TERMINAL_GEAR

Curated for the Linux community

KIWITATA 2X Classic SNES USB Controller for PC Gamings, Retro SNES Wired USB Game Emulator Controller for Windows XP 7 8 11 Mac Raspberry Pi

KIWITATA 2X Classic SNES USB Controller for PC Gamings, Retro SNES Wired USB Game Emulator Controller for Windows XP 7 8 11 Mac Raspberry Pi

$16.99
Raspberry Pi 5 8GB

Raspberry Pi 5 8GB

$134.50
Lenovo Gen 13 ThinkPad X1 Carbon Touchscreen Laptop with Intel Ultra 7 265U Processor, 14" WUXGA 100% sRGB, 32GB DDR5 RAM, 1TB NVMe Performance SSD, FHD+ IR+ RGB Camera, and Windows 11 Pro

Lenovo Gen 13 ThinkPad X1 Carbon Touchscreen Laptop with Intel Ultra 7 265U Processor, 14" WUXGA 100% sRGB, 32GB DDR5 RAM, 1TB NVMe Performance SSD, FHD+ IR+ RGB Camera, and Windows 11 Pro

$1,589.00
Copied to clipboard

> TERMINAL_GEAR

Curated for the Linux community

GMKtec Gaming PC, K11 AMD Ryzen 9 8945HS, 32GB DDR5 RAM 1TB Mini PC Desktop Computer, Oculink, Dual NIC 2.5GbE LAN, HDMI/DisplayPort/USB4*2

GMKtec Gaming PC, K11 AMD Ryzen 9 8945HS, 32GB DDR5 RAM 1TB Mini PC Desktop Computer, Oculink, Dual NIC 2.5GbE LAN, HDMI/DisplayPort/USB4*2

$739.99
Lenovo Gen 13 ThinkPad X1 Carbon Touchscreen Laptop with Intel Ultra 7 265U Processor, 14" WUXGA 100% sRGB, 32GB DDR5 RAM, 1TB NVMe Performance SSD, FHD+ IR+ RGB Camera, and Windows 11 Pro

Lenovo Gen 13 ThinkPad X1 Carbon Touchscreen Laptop with Intel Ultra 7 265U Processor, 14" WUXGA 100% sRGB, 32GB DDR5 RAM, 1TB NVMe Performance SSD, FHD+ IR+ RGB Camera, and Windows 11 Pro

$1,589.00
Raspberry Pi 5 8GB

Raspberry Pi 5 8GB

$134.50