There's a built-in function,
sgml-pretty-print, but it's really slow. When
running it on some large XML files, it's locked up Emacs for minutes for me.
Running xmlstarlet on the same file was instantaneous.
brew install xmlstarlet
Navigate to the file in a dired buffer, and hit
to run a shell command on the file. Type:
xmlstarlet ed --inplace.