ppx – Pretty Print XML¶
ppx pretty prints an XML source in human readable form.
Examples¶
ppx will try to use the character encoding of your terminal and defaults to UTF-8.
Pretty print any local XML file:
ppx file.xml
Pretty print an RSS feed:
ppx http://feeds.feedburner.com/PythonInsider
Page an XML file with less:
ppx xml/large.xml | less -RX
Redirect output (pipe) to ppx:
curl -s https://peps.python.org/peps.rss | ppx
Options¶
ppx can be used with the following command-line options:
$ ppx --help
usage: ppx [-h] [-V] [-n] [-o] [xml_source ...]
Pretty Print XML source in human readable form.
positional arguments:
xml_source XML source (file, <stdin>, http://...)
options:
-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
White Space¶
For greater readability ppx removes and adds white space.
Rewrite an XML file:
ppx -n data_dump.xml > pp_data_dump.xml
Warning
White space can be significant in an XML document [1].
So be careful when using ppx to rewrite XML files.
Output options¶
ppx terminal output options.
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:
ppx --no-syntax http://www.w3.org/2001/XMLSchema.xsd
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
Footnotes