How To Pretty Print and Format XML In Command Line Linux?

RSS
EMAIL
FACEBOOK
FACEBOOK
GOOGLE
GOOGLE
https://www.poftut.com/pretty-print-format-xml-command-line-linux/
PINTEREST
PINTEREST
INSTAGRAM

XML or extensible markup language is popular data structure used to express data in a exchangeable format. It is mostly used for configuration and data exchange between web services. While inspecting some XML in Linux via command line we generally need to print in a more readable and structured way. In this tutorial we will look how to pretty print XML in Linux command line.

Xmllint

xmllint  is a tool provided by libxml2-utils  package. It can be installed like below for deb based distributions like Debian, Ubuntu, Mint and Kali

Or rpm based distributions like Fedora, CentOS, RedHat

We can format xml file named data.xml  like below by providing --format  option.

Xmllint

Xmllint

Xml_pp

xml_pp  is provided by xml-twig-tools  and can be installed like below.

OR

We can use xml_pp  wiothout providing any option just providing the XML file name like below.

Xmlstarlet

xmlstarlet  is single tool which can format XML in different ways. We can install xmlstarlet for deb based distributions like below.

Or rpm based distribuıtions

We will use format  and --indent-tab  for the command and tab indentation.

LEARN MORE  Nmap Output

Xmlstarlet

Xmlstarlet

Tidy

tidy  tool is developed to read and write cleaned-up markup for HTMLiXHTML and XML files. We can install for Ubuntu, Debian, Mint and Kali like below.

OR for Fedora, CentOS, RedHat

We will use -xml  to specify the file data format and -i  for indentation.

Tidy

Tidy

As we can see tidy provides error or warning information before printing formatted xml.

Python XML Library

Yes python have a lot of libraries and one of them is xml  library which can be used to create or parse XML data. We can use xml.dom.minidom module parseString() functions like below. We will redirect data of the XML file named data.xml .

Python XML Library

Python XML Library

RSS
EMAIL
FACEBOOK
FACEBOOK
GOOGLE
GOOGLE
https://www.poftut.com/pretty-print-format-xml-command-line-linux/
PINTEREST
PINTEREST
INSTAGRAM

You may also like...

Leave a Reply

Your email address will not be published.

Enjoy this blog? Please spread the word :)