A Code Monkey's Blog

Indent only XML file

Recently I have worked on editing XML files in Vim. These XML files are the documents of a software in DocBook style. Since they are maintained manually, the indentation is badly formatted. So before getting deeper, the very first thing to do was to re-indent the files. It turned out from a short Google search that the tools to get the job done could be:

xmllint, xmlindent and tidy seem to remove the empty lines I left intentionally, which is bad since I want to keep them for readability. xmlformat seems to provide such options to add blank lines but I didn't have time to look into. So finally I only used 'gg=G' in Vim to format the XML file. This operation was only to indent the file without combining or removing any blank lines. That was just what I needed.