You can format XML in vi using xmllint
:%!xmllint "%" --format
Default indentation is 2 spaces. You can change that by assigning a value to the XMLLINT_INDENT environment variable. To do that without leaving vi,
:let $XMLLINT_INDENT=" "
Then just run the same command as before.
If you have tidy
installed, you can use it instead of xmllint
:% !tidy -q --input-xml true --indent yes --indent-spaces 4 %