How to pretty print XML on GNU/Linux

GNU/Linux
The obfuscated XML files are difficult to read because the content of the file occupies a single line. Today LibreByte offers 3 tools that allow you to format an XML file.

Tool 1: web browser, examples: Mozilla firefox, Google Chrome. The disadvantage of using a browser is that you can not edit the XML file, only useful if you if you want to view it and nothing more.

Tool 2: use xml_pp, xml_pp is part of the XML-Twig suite, to install it on Debian GNU/Linux type:

$ sudo apt-get install xml-twig-tools

You can then format the XML file by typing:

$ xml_pp -i mifichero.xml

If you want to save the formatted content in another file, type:

$ xml_pp mifichero.xml > mifichero_pp.xml 

If you want to edit the formatted file, you can use any text editor.

Tool 3: Use Geany editor and prettyprinter plugin, to install it on Debian GNU/Linux type:

$ sudo apt-get install geany geany-plugin-prettyprinter

After running the above command, you must perform the following steps to activate the plugin

1. Run Geany
XFCE:

Menu-> Development-> Geany

From the console, you can also type:

$ geany &

2. Find the Menu

Tools -> Plugin Manager

3. Activate the plugin XML PrettyPrinter

Once the plugin is activated, the option to format XML appears in the Menu:

Tools-> PrettyPtrinter XML

Further reading

- man xml_pp
- Geany Project
- XML-Twig
- Geany un IDE ligero

The tutorials here on LibreByte are provided under a free software licence. if you like my work you should consider:
Buy a Hosting/VPS or Dedicated Server at MCKHost

1 comment

    • JanKurz on October 14, 2020 at 7:42 am
    • Reply

    Thank you for sharing this - really helpful!
    I did not know about Geany and the geany-plugin-prettyprinter Package.
    Just installed it and it works like a charme!

Leave a Reply

Your email address will not be published.

This site uses Akismet to reduce spam. Learn how your comment data is processed.