Is there any CLI tool for Linux which formats XML files keeping any empty lines and comments? I have tried xmllint, tidy and xmlstarlet, but all seem to focus completely cleaning XML files rather than just indentation and spacing. Answer Try xmlindent. It has several options like -nbe and -nba and others that configure the handling of spaces before and