xmllint support formatting in-place:
for f in *.xml; do xmllint -o $f --format $f; done
As Daniel Veillard has written:
I think
xmllint -o tst.xml --format tst.xml
should be safe as the parser will fully load the input into a tree
before opening the output to serialize it.
Indent level is controlled by XMLLINT_INDENT
environment variable which is by default 2 spaces. Example how to change indent to 4 spaces:
XMLLINT_INDENT=' ' xmllint -o out.xml --format in.xml
You may have lack with --recover
option when you XML documents are broken. Or try weak HTML parser with strict XML output:
xmllint --html --xmlout <in.xml >out.xml
--nsclean
, --nonet
, --nocdata
, --noblanks
etc may be useful. Read man page.
apt-get install libxml2-utils
dnf install libxml2
apt-cyg install libxml2
brew install libxml2
xmllint
available on Debian systems, you need to install the packagelibxml2-utils
(libxml2
does not provide this tool, at least not on Debian 5.0 "Lenny" and 6.0 "Squeeze"). – Heyer