unix - How to pretty print XML from the command line? -
related: how can pretty-print json in (unix) shell script?
is there (unix) shell script format xml in human-readable form?
basically, want transform following:
<root><foo a="b">lorem</foo><bar value="ipsum" /></root> ... this:
<root> <foo a="b">lorem</foo> <bar value="ipsum" /> </root>
try doing :
echo '<root><foo a="b">lorem</foo><bar value="ipsum" /></root>' | xmllint --format - this utility comes libxml2-utils
or
echo '<root><foo a="b">lorem</foo><bar value="ipsum" /></root>' | xml_pp this command comes xml::twig perl module, xml-twig-tools package.
or
echo '<root><foo a="b">lorem</foo><bar value="ipsum" /></root>' | xmlstarlet format --indent-tab this command comes 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
Comments
Post a Comment