Related: How can I pretty-print JSON in a shell script?
Is there a (Unix) shell script to format XML content in human-readable form?
Basically, I want it to transform the following:
<root><foo a="b">lorem</foo><bar value="ipsum" /></root>
... into something like this:
<root>
<foo a="b">lorem</foo>
<bar value="ipsum" />
</root>
xmllint --format file.xml
(On Debian-based distributions, install the libxml2-utils package.)
xml_pp < file.xml
(On Debian-based distributions, install the xml-twig-tools package.)
xmlstarlet format --indent-tab file.xml
tidy -xml -i -q file.xml
echo '<root><foo a="b">lorem</foo><bar value="ipsum" /></root>' |
python -c 'import sys, xml.dom.minidom; print(xml.dom.minidom.parseString(sys.stdin.read()).toprettyxml())'
saxon-lint --indent --xpath '/' file.xml
echo '<root><foo a="b">lorem</foo><bar value="ipsum" /></root>' |
java -cp /usr/share/java/saxon/saxon9he.jar net.sf.saxon.Query \
-s:- -qs:/ '!indent=yes'
xidel --output-node-format=xml --output-node-indent -se . -s file.xml
(Credit to Reino)
<root>
<foo a="b">lorem</foo>
<bar value="ipsum"/>
</root>