ppx – Pretty Print XML¶
Use ppx to pretty print an XML source in human readable form.
ppx file.xml
White Space¶
For greater readability ppx removes and adds white space.
Warning
White space can be significant in an XML document [1].
So be careful when using ppx to rewrite XML files.
Options¶
ppx can be used with the following command-line options:
$ ppx --help
usage: ppx [-h] [-V] [-n] [-o] [xml_source [xml_source ...]]
Pretty Print XML source in human readable form.
positional arguments:
xml_source XML source (file, <stdin>, http://...)
optional arguments:
-h, --help show this help message and exit
-V, --version show program's version number and exit
-n, --no-syntax no syntax highlighting
-o, --omit-declaration
omit the XML declaration
Syntax Highlighting¶
ppx will syntax highlight the XML source if you have Pygments installed.
Pretty print the XML Schema 1.0 schema document:
ppx http://www.w3.org/2001/XMLSchema.xsd
- -n, --no-syntax¶
You can disable syntax highlighting with the --no-syntax option.
XML declaration¶
XML documents should begin with an XML declaration which specifies the version of XML being used [2].
By default ppx will print an (UTF-8) XML declaration.
- -o, --omit-declaration¶
Omit the XML declaration with the --omit-declaration option.
ppx --omit-declaration file.xml
Examples¶
Pretty print any local XML file:
ppx data_dump.xml
RSS feed:
ppx http://feeds.feedburner.com/PythonInsider
Page XML file with less:
ppx xml/large.xml | less -RX
Redirect output (pipe) to ppx:
curl -s https://peps.python.org/peps.rss | ppx
ppx -n data_dump.xml > pp_data_dump.xml
Footnotes