Try doing this :
echo '<root><foo a="b">lorem</foo><bar value="ipsum" /></root>' |
xmllint --format -
This utility comes with libxml2-utils
or
echo '<root><foo a="b">lorem</foo><bar value="ipsum" /></root>' |
xml_pp
this command comes with XML::Twig perl module, sometimes xml-twig-tools package.
or
echo '<root><foo a="b">lorem</foo><bar value="ipsum" /></root>' |
xmlstarlet format --indent-tab
this command comes with xmlstarlet
or
echo '<root><foo a="b">lorem</foo><bar value="ipsum" /></root>' |
tidy -xml -i -
check tidy package
or
echo '<root><foo a="b">lorem</foo><bar value="ipsum" /></root>' |
python -c 'import sys;import xml.dom.minidom;s=sys.stdin.read();print xml.dom.minidom.parseString(s).toprettyxml()'
or
echo '<root><foo a="b">lorem</foo><bar value="ipsum" /></root>' |
saxon-lint --indent --xpath '/' -
check saxon-lint
or
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'
Check saxon-HE