XML formatting Indentation Tags Matching - Linux XML formatting Indentation Tags Matching - Linux bash bash

XML formatting Indentation Tags Matching - Linux


xmllint --format <your-xml-file>

example

$ cat test.xml<a><b>c</b></a>$ xmllint --format test.xml<a>  <b>c</b></a>$ xmllint --format test.xml > test.formatted.xml$ cat test.formatted.xml<a>  <b>c</b></a>$


tidy -xml -i -q

-xml - specify the input is well formed XML

-q - suppress nonessential output

-i - indent element content

tidy can work with files and stdin/stdout

echo '<a><b>c</b></a>' | tidy -xml -i -q

will produce

    <a>      <b>c</b>    </a>