Skip to content

Latest commit

 

History

History
66 lines (40 loc) · 1.85 KB

File metadata and controls

66 lines (40 loc) · 1.85 KB

xmlfmt

Format XML

Usage

xmlfmt [options] [file|-]

If no input file is provided, xmlfmt reads from stdin. If no mode is specified, xmlfmt defaults to pretty output.

Modes

  • --pretty: Emit pretty-printed XML
  • --compact: Emit compact XML
  • --indent: Pretty indent style, either tab or an integer number of spaces (default: 2)

Only one of --pretty or --compact may be used.

XML Transform Options

  • --sort-elements: Sort child elements recursively by tag name
  • --default-namespace: Set or switch the default namespace on the root element
  • --clear-default-namespace: Remove the default namespace from the root element
  • --remove-namespace: Remove a namespace by prefix or URI (repeatable)
  • --named-entities-to-numeric: Convert HTML named entities to numeric entities
  • --remove-doctype: Remove the DOCTYPE directive
  • --set-doctype: Set the DOCTYPE directive (with or without leading DOCTYPE)
  • --remove-declaration: Remove the XML declaration
  • --set-declaration: Set XML declaration content, for example version="1.0" encoding="UTF-8"

Only one of --remove-doctype or --set-doctype may be used. Only one of --remove-declaration or --set-declaration may be used.

Output Options

  • --trailing-newline: Emit a trailing newline
  • --eol: End-of-line style, one of lf, cr, or crlf (default: lf)

Standard Flags

  • --help, -h: Show help message
  • --version: Print version information

Examples

Pretty print a file with 4-space indentation:

xmlfmt --pretty --indent 4 input.xml

Compact output from stdin:

cat input.xml | xmlfmt --compact

Sort elements and change the default namespace:

xmlfmt --sort-elements --default-namespace urn:example input.xml

Remove one namespace prefix and convert named entities:

xmlfmt --remove-namespace a --named-entities-to-numeric input.xml

Remove declaration and doctype:

xmlfmt --remove-declaration --remove-doctype input.xml