xml-format
Format and indent XML files
TLDR
Format an XML document, indenting with tabs
Format an HTML document, indenting with 4 spaces
Recover parsable parts of a malformed XML document, without indenting
Format an XML document from stdin, removing the DOCTYPE declaration
Format an XML document, omitting the XML declaration
Display help
SYNOPSIS
N/A
There is no universally recognized 'xml-format' command with a standard synopsis. The method for formatting XML depends on the specific tool used, such as xmllint or xmlstarlet.
DESCRIPTION
The command xml-format is not a standard, standalone utility widely available across all Linux distributions.
Typically, when users refer to 'xml-format' on Linux, they are describing the action of pretty-printing or re-indenting an XML document for better readability, rather than invoking a specific command named exactly 'xml-format'.
The functionality of formatting XML is commonly provided by various XML processing tools available in Linux environments. These tools read an XML input (from a file or standard input) and output a reformatted version, often with proper indentation and line breaks, adhering to XML well-formedness rules.
Common utilities used for this purpose include xmllint (part of the libxml2-utils package) and xmlstarlet (a separate command-line XML toolkit). These tools offer robust features for parsing, validating, transforming, and formatting XML documents.
CAVEATS
The primary caveat is that xml-format is not a direct command. Attempting to execute 'xml-format' directly on most Linux systems will result in a 'command not found' error.
Users must install and utilize specific XML processing tools (like xmllint or xmlstarlet) to achieve XML formatting. Each tool has its own syntax, options, and capabilities, which need to be consulted via their respective manual pages.
COMMON METHODS FOR XML FORMATTING
While 'xml-format' is not a direct command, here are the most common ways to achieve XML formatting on Linux:
1. Using xmllint:
xmllint is a command-line tool for parsing, validating, and formatting XML and HTML documents. It's often pre-installed or easily available via the 'libxml2-utils' package.
Syntax: xmllint --format [file.xml]
Example: cat input.xml | xmllint --format - > output.xml
2. Using xmlstarlet:
xmlstarlet is a powerful command-line XML toolkit that can validate, transform, query, and edit XML documents. Its 'format' subcommand is specifically for pretty-printing.
Syntax: xmlstarlet fo [file.xml]
Example: xmlstarlet fo input.xml > output.xml
SEE ALSO
xmllint(1), xmlstarlet(1), tidy(1)