|
| 1 | +# xmlfmt |
| 2 | + |
| 3 | +Format XML |
| 4 | + |
| 5 | +## Usage |
| 6 | + |
| 7 | +xmlfmt [options] [file|-] |
| 8 | + |
| 9 | +If no input file is provided, xmlfmt reads from stdin. |
| 10 | +If no mode is specified, xmlfmt defaults to pretty output. |
| 11 | + |
| 12 | +## Modes |
| 13 | + |
| 14 | +* --pretty: Emit pretty-printed XML |
| 15 | +* --compact: Emit compact XML |
| 16 | +* --indent: Pretty indent style, either tab or an integer number of spaces (default: 2) |
| 17 | + |
| 18 | +Only one of --pretty or --compact may be used. |
| 19 | + |
| 20 | +## XML Transform Options |
| 21 | + |
| 22 | +* --sort-elements: Sort child elements recursively by tag name |
| 23 | +* --default-namespace: Set or switch the default namespace on the root element |
| 24 | +* --clear-default-namespace: Remove the default namespace from the root element |
| 25 | +* --remove-namespace: Remove a namespace by prefix or URI (repeatable) |
| 26 | +* --named-entities-to-numeric: Convert HTML named entities to numeric entities |
| 27 | +* --remove-doctype: Remove the DOCTYPE directive |
| 28 | +* --set-doctype: Set the DOCTYPE directive (with or without leading DOCTYPE) |
| 29 | +* --remove-declaration: Remove the XML declaration |
| 30 | +* --set-declaration: Set XML declaration content, for example version="1.0" encoding="UTF-8" |
| 31 | + |
| 32 | +Only one of --remove-doctype or --set-doctype may be used. |
| 33 | +Only one of --remove-declaration or --set-declaration may be used. |
| 34 | + |
| 35 | +## Output Options |
| 36 | + |
| 37 | +* --trailing-newline: Emit a trailing newline |
| 38 | +* --eol: End-of-line style, one of lf, cr, or crlf (default: lf) |
| 39 | + |
| 40 | +## Standard Flags |
| 41 | + |
| 42 | +* --help, -h: Show help message |
| 43 | +* --version: Print version information |
| 44 | + |
| 45 | +## Examples |
| 46 | + |
| 47 | +Pretty print a file with 4-space indentation: |
| 48 | + |
| 49 | +xmlfmt --pretty --indent 4 input.xml |
| 50 | + |
| 51 | +Compact output from stdin: |
| 52 | + |
| 53 | +cat input.xml | xmlfmt --compact |
| 54 | + |
| 55 | +Sort elements and change the default namespace: |
| 56 | + |
| 57 | +xmlfmt --sort-elements --default-namespace urn:example input.xml |
| 58 | + |
| 59 | +Remove one namespace prefix and convert named entities: |
| 60 | + |
| 61 | +xmlfmt --remove-namespace a --named-entities-to-numeric input.xml |
| 62 | + |
| 63 | +Remove declaration and doctype: |
| 64 | + |
| 65 | +xmlfmt --remove-declaration --remove-doctype input.xml |
| 66 | + |
0 commit comments