dlog developer log

12Feb/102

Format XML in VIM

Sometimes when you're working with a messy or hard to read XML document, it helps to re-format or pretty-print the XML.  It's easy to re-indent the XML with the command

gg=G

But what if the XML is all on one line, or has an otherwise messy linebreak structure?  The built-in VIM indentation command can't help there, but  xmllint -- a utility that comes with libxml -- can.

  1. Download xmllint
    For Windows you'll need libxml and zlib from GnuWin32.   To obtain libxml, try Igor Zlatković's win32 builds of libxml.  Extract xmllint.exe and libxml2.dll into a directory in your PATH.  Download zlib from the GnuWin32 zlib page.  Extract zlib1.dll into a directory in your PATH.
  2. Send the VIM edit buffer through xmllint
    :%!xmllint --format -
Comments (2) Trackbacks (0)
  1. Appreciate it for spending time on this

  2. I didn’t know about gg=G, so that actually got me what I wanted. :) Thanks much for sharing – seems like there’s always something new to learn with vim…


Leave a comment

No trackbacks yet.