XMLLINT(1)

๐Ÿ’– XMLLINT(1) โ€” the xmllint manual, bestie edition ๐Ÿ’–

okay so welcome to xmllint, from the xmllint Manual (that's the manual name, keep it in your notes ๐Ÿ“). it's a command line XML tool and honestly? it's giving main character energy for anyone who lives in a terminal and also lives in XML files. we're doing this in parts because there's a LOT, so buckle up ๐ŸŽ€


โœจ NAME โœจ

xmllint โ€” command line XML tool. that's the whole vibe. one job, many flags. ๐Ÿ’…


๐Ÿฆ‹ SYNOPSIS ๐Ÿฆ‹

xmllint [--version | --debug | --quiet | --shell |
        --xpath "XPath_expression" | --xpath0 "XPath_expression" |
        --copy | --recover | --huge | --nocompact | --nodefdtd |
        --nodict | --noenc | --noent | --nofixup-base-uris | --noout |
        --nonet | --path "PATH(S)" | --load-trace | --valid |
        --postvalid | --dtdvalid URL | --dtdvalidfpi FPI | --timing |
        --output FILE | --repeat | --insert | --strict-namespace |
        --compress | --html | --xmlout | --push | --memory |
        --max-ampl INTEGER | --maxmem NBBYTES | --nowarning | --noblanks
        | --nocdata | --format | --pretty INTEGER | --encode ENCODING |
        --dropdtd | --nsclean | --catalogs | --nocatalogs | --auto |
        --xinclude | --noxincludenode | --loaddtd | --dtdattr | --stream
        | --walker | --pattern PATTERNVALUE | --relaxng SCHEMA |
        --schema SCHEMA | --schematron SCHEMA | --c14n | --c14n11 |
        --exc-c14n | --pedantic | --sax | --sax1 | --oldxml10]
        {XML-FILE(S)... | -}

likeโ€ฆ look at all those flags. no cap, she's got options. ๐Ÿ‘‘


๐ŸŒธ DESCRIPTION ๐ŸŒธ

so xmllint parses one or more XML files, and you hand them over on the command line as XML-FILE โ€” or, if the filename you provide is -, she'll just read from standard input instead. slay, stdin rep ๐Ÿ’–

she prints various types of output depending on which options you picked, and she's genuinely useful for detecting errors both in XML code and in the XML parser itself. like a little error-detecting bestie. ๐Ÿ”

and for the record: xmllint is part of the libxml2 library. iykyk. ๐Ÿ“š


โœ… VALIDATION OPTIONS โœ…

these are the options that enable validation. vibe check your documents, fr fr.

  • --dtdvalid URL โ€” validate using the DTD that lives at an URL. go fetch, bestie ๐Ÿซถ
  • --dtdvalidfpi FPI โ€” validate using the DTD identified by a Formal Public Identifier FPI. heads up though: this needs a catalog that exports that Formal Public Identifier, otherwise it simply won't work. no catalog, no service ๐Ÿ’€
  • --relaxng SCHEMA โ€” validate using the RelaxNG file named SCHEMA.
  • --schema SCHEMA โ€” validate using the W3C XML Schema file named SCHEMA.
  • --schematron SCHEMA โ€” validate using the Schematron file named SCHEMA.
  • --valid โ€” figures out if the document is a valid instance of the Document Type Definition (DTD) it includes. you can also point at a DTD to validate against straight from the command line with the --dtdvalid option. and by default, xmllint also checks whether the document is well-formed. she's thorough like that. ๐Ÿ’…
  • --strict-namespace โ€” throws an error if the document is well-formed but has namespace errors. this one enforces namespace-well-formedness. strict queen. ๐Ÿ‘‘

๐Ÿงš PARSER OPTIONS ๐Ÿงš

these set the respective parser options. one bullet each, no skipping, promise ๐Ÿคž

  • --dtdattr โ€” fetch the external DTD and populate the tree with inherited attributes. this one implies --loaddtd.
  • --huge โ€” ignore some hardcoded parser limits. big girl energy ๐Ÿ”ฅ
  • --loaddtd โ€” fetch an external DTD and external parameter entities.
  • --max-ampl INTEGER โ€” sets the maximum amplification factor, which is what protects you against exponential entity expansion (aka the "billion laughs" attack ๐Ÿ˜ญ). the default value is 5. documents that make heavy use of entity expansion may need a higher value.
  • --noblanks โ€” drops "ignorable" blank spaces. and bestie, listen: this option is unreliable and shouldn't be used. not me warning you twice. ๐Ÿ™ˆ
  • --nocatalogs โ€” do not use any catalogs.
  • --nocdata โ€” substitute CDATA sections with equivalent text nodes.
  • --nodefdtd โ€” do not set the default HTML doctype (parser option HTML_PARSE_NODEFDTD).
  • --noenc โ€” ignore the encoding declaration (parser option XML_PARSE_IGNORE_ENC).
  • --noent โ€” substitute entity values in place of entity references. by default xmllint leaves entity references in place. this option enables loading of external DTDs and entities.
  • --nofixup-base-uris โ€” don't fix xml:base URIs when processing XIncludes (parser option XML_PARSE_NOBASEFIX).
  • --nonet โ€” do not use the Internet to fetch DTDs or entities. heads up: this has no effect with libxml2 2.15 or later.
  • --nowarning โ€” do not emit warnings from the parser and/or validator. (we love a quiet queen but you might miss stuff ๐Ÿ’€)
  • --nsclean โ€” remove redundant namespace declarations.
  • --oldxml10 โ€” use deprecated parsing rules from before XML 1.0, 5th edition.
  • --pedantic โ€” enable additional warnings. she's watching ๐Ÿ‘€
  • --recover โ€” output any parsable portions of an invalid document. exact behavior is unspecified, and use of this option is discouraged. seriously, proceed with caution bestie.
  • --xinclude โ€” do XInclude processing.

๐ŸŽ€ MISCELLANEOUS OPTIONS ๐ŸŽ€

the options that don't fit in any other category. the little weirdos. we stan. ๐Ÿซถ

  • --catalogs โ€” use the SGML catalog(s) from SGML_CATALOG_FILES. note that XML catalogs are loaded by default.
  • --dropdtd โ€” remove the DTD after parsing. bye bye ๐Ÿ‘‹
  • --html โ€” use the HTML parser.
  • --path "PATH(S)" โ€” use the (space- or colon-separated) list of filesystem paths given by PATHS to load DTDs or entities. if your list is space-separated, wrap it in quotation marks or she will simply not understand you. ๐Ÿ’…
  • --quiet โ€” don't print informational messages to stderr. peace and quiet, periodt.
  • --sax โ€” print SAX callbacks for debugging. you can also use it for streaming DTD and Schema validation when you pair it with --noout.
  • --shell โ€” run a navigating shell. the details on the commands available in shell mode are further down (see the section called โ€œSHELL COMMANDSโ€). interactive era โœจ
  • --stream โ€” use the streaming API. super useful when combined with the --relaxng or --valid options for validating files that are too large to be held in memory. big file, small RAM, no problem.
  • --version โ€” display the version of libxml2 used.

๐Ÿ’… OUTPUT OPTIONS ๐Ÿ’…

these control output. important caveat: except for --noout, these have no effect in SAX or stream mode. remember that fr fr.

  • --compress โ€” turn on gzip(1) compression of output.
  • --c14n, --c14n11, --exc-c14n โ€” use the W3C XML Canonicalisation (C14N) to serialize the result of parsing to stdout. it keeps comments in the result.
  • --encode ENCODING โ€” output in the given encoding. note that this works for a full document, not for fragments or results from XPath queries.
  • --format โ€” reformat and reindent the output. the XMLLINT_INDENT environment variable controls the indentation, and the default value is two spaces (" ").
real talk: especially when there's no DTD, this feature has never worked reliably and is fundamentally broken. iconic behaviour, honestly. ๐Ÿ’€
  • --noout โ€” suppress output. by default, xmllint outputs the result tree.
  • --output FILE โ€” define a file path where xmllint will save the result of parsing. usually the programs build a tree and save it on stdout; with this option, the resulting XML instance gets saved onto a file instead. โœจ
  • --pretty INTEGER โ€” value 0 means no formatting, 1 means XML_SAVE_FORMAT (same as --format), and 2 means XML_SAVE_WSNONSIG.
  • --xmlout โ€” used together with --html. normally when HTML is parsed the document is saved with the HTML serializer, but with this option the resulting document is saved with the XML serializer instead. it's primarily used to generate XHTML from HTML input. glow-up pipeline ๐ŸŒˆ

๐Ÿ”ฅ DEBUG OPTIONS ๐Ÿ”ฅ

these ones let you debug the libxml2 library itself. but listen: the behavior of these options may change without notice. no promises, no cap.

  • --auto โ€” generate a small document for testing purposes.
  • --copy โ€” test the internal copy implementation.
  • --debug โ€” parse a file and output an annotated tree of the in-memory version of the document. ๐ŸŒณ
  • --insert โ€” test for valid insertions. DEPRECATED: this feature will be removed. rip bestie ๐Ÿชฆ
  • --load-trace โ€” display all the documents loaded during processing, to stderr.
  • --maxmem NNBYTES โ€” test the parser memory support. NNBYTES is the maximum number of bytes the library is allowed to allocate. you can also use this to make sure that batch processing XML files won't exhaust the virtual memory of the server running them. protect the server, protect the vibe ๐Ÿ›ก๏ธ
  • --memory โ€” parse from memory.
  • --nocompact โ€” do not generate compact text nodes (parser option XML_PARSE_COMPACT). only for debugging.
  • --nodict โ€” don't use dictionaries (parser option XML_PARSE_NODICT). only for debugging.
  • --noxincludenode โ€” do XInclude processing, but don't generate XInclude start and end nodes.
  • --pattern PATTERNVALUE โ€” used to exercise the pattern recognition engine, which can be used with the reader interface to the parser. it lets you select some nodes in the document based on an XPath (subset) expression. used for debugging.
  • --postvalid โ€” validate after parsing has completed. late validation, still valid ๐Ÿ’…
  • --push โ€” use the push mode of the parser.
  • --repeat โ€” repeat 100 times, for timing or profiling. girl is doing reps ๐Ÿ‹๏ธ
  • --sax1 โ€” use the deprecated SAX1 interface (only for debugging).
  • --timing โ€” output information about how long it takes xmllint to perform the various steps. โฑ๏ธ
  • --walker โ€” test the walker module, which is a reader interface but for a document tree: instead of using the reader API on an unparsed document, it works on an existing in-memory tree. used for debugging.
  • --xpath "XPath_expression" โ€” run the XPath expression given as the argument and print the result. if the result is a nodeset, every node in the node set is serialized in full in the output. and if the node set is empty, you'll get the "XPath set is empty" result and exit code 11 will be returned.. (yes, that's a double period, i'm just being faithful ๐Ÿ˜ญ)

๐Ÿš SHELL COMMANDS ๐Ÿš

so xmllint offers an interactive shell mode, which you invoke with the --shell command. the commands available in shell mode include (in alphabetical order, because we're organized like that โœจ):

  • base โ€” display the XML base of the node.
  • bye โ€” leave the shell. ๐Ÿ‘‹
  • cat NODE โ€” display the given node, or the current one.
  • cd PATH โ€” change the current node to the given path (if it's unique), or to the root if no argument is given.
  • dir PATH โ€” dumps information about the node (namespace, attributes, content).
  • du PATH โ€” show the structure of the subtree under the given path, or under the current node.
  • exit โ€” leave the shell.
  • help โ€” show this help. ๐Ÿ†˜
  • load FILENAME โ€” load a new document with the given filename.
  • ls PATH โ€” list the contents of the given path or the current directory.
  • pwd โ€” display the path to the current node.
  • quit โ€” leave the shell.
  • save FILENAME โ€” save the current document to the given filename, or to the original name.
  • validate โ€” check the document for errors.
  • write FILENAME โ€” write the current node to the given filename.

and that's part 1, bestie โ€” there's more coming, so don't go anywhere ๐Ÿ’–

๐ŸŒฟ ENVIRONMENT (aka the vibes your shell passes down to me) ๐ŸŒฟ

okay so bestie, before we even get to the exit codes, lemme tell you about the environment variables, because these are the little knobs your shell can turn to change how I behave. no cap, they're lowkey important.

  • SGML_CATALOG_FILES โ€” so you can change how SGML catalog behavior works by redirecting queries to your own set of catalogs ๐ŸŽ€. how? set this variable to a list of catalogs, that's it, that's the whole move. and listen: an empty one should deactivate loading the default catalog. yes, empty. periodt.
  • XML_CATALOG_FILES โ€” same energy, but for XML catalogs โœจ. set it to a space-separated list of catalogs to redirect queries to your own set. and because spaces are the separator, use percent-encoding to escape spaces or other characters (iykyk). an empty variable should deactivate loading the default catalog, same as above ๐Ÿ’….
  • XML_DEBUG_CATALOG โ€” want the tea on what the catalogs are doing?? set this to non-zero using the export command and I'll output debugging information related to catalog operations ๐Ÿ”. not me being nosy, it's a feature.
  • XMLLINT_INDENT โ€” this one controls the indentation ๐Ÿ’–. the default value is two spaces " ". that's it. that's the whole default. iconic.

๐Ÿ’€ DIAGNOSTICS (the return codes, aka my receipts) ๐Ÿ’€

my return codes give you info you can actually use when you're calling me from scripts. so like, if statements and && chains and all that main character shell scripting energy ๐Ÿซถ.

here's the full rundown, no skips, no summarising, we go all the way down:

  • 0 โ€” No error ๐ŸŒˆ. we ate, literally nothing went wrong.
  • 1 โ€” Unclassified ๐Ÿ˜ญ. it's giving "something happened and we're not putting a label on it".
  • 2 โ€” Error in DTD ๐Ÿ’€.
  • 3 โ€” Validation error ๐Ÿ™ˆ.
  • 4 โ€” Document isn't well-formed or couldn't be read ๐Ÿ˜ญ. two for one, tragic either way.
  • 5 โ€” Error in schema compilation ๐Ÿงš.
  • 6 โ€” Error writing output โœ๏ธ.
  • 7 โ€” Error in pattern (generated when --pattern option is used) ๐ŸŒธ.
  • 9 โ€” Out of memory error ๐Ÿ’€. oh she's struggling.
  • 10 โ€” XPath evaluation error ๐Ÿ”ฅ.
  • 11 โ€” XPath result is empty ๐Ÿ•ณ๏ธ.
bestie there is literally no 8 in this list. I'm not hiding it from you, it's just not here. don't come for me about it, I didn't write the numbers ๐Ÿ’….

๐Ÿ‘€ SEE ALSO

more information can be found in the libxml2 repo at https://gitlab.gnome.org/GNOME/libxml2 โ€” go forth and read, it's right there, go get your education ๐Ÿฆ‹.


๐Ÿ‘‘ AUTHORS (the legends, the icons, the moment)

  • John Fleck <jfleck@inkstain.net>
  • Ziying Sherwin <sherwin@nlm.nih.gov>
  • Heiko Rupp <hwr@pilhuhn.de>

three whole humans made this happen and we're obsessed with them fr fr ๐Ÿ’œ.


Copyright ยฉ 2001, 2004


and that's the whole page, bestie!! ๐Ÿซถ this was xmllint, and it's hanging out at version/date 09/04/2026 in XMLLINT(1). go forth, validate things, read your exit codes, and remember: an empty catalog variable deactivates the default catalog, and no I will not stop bringing it up โœจ๐ŸŒธ๐Ÿ’–

๐Ÿ“ฆ where this page comes from