Formatting XML documents using Vi and Xmllint

Submitted by Jochus on Thu, 07/02/2013 - 14:48 | Posted in: Mac

If you want to format the following XML document:

<?xml version="1.0" encoding="UTF-8"?><ROOT><FOO><BAR>Hello World</BAR></FOO><BAR><FOO>World Hello</FOO></BAR></ROOT>

... you can use Vi in combination with Xmllint to do the formatting

$ vi example.xml
:%!xmllint --format -

... the result will be:

<?xml version="1.0" encoding="UTF-8"?>
    <BAR>Hello World</BAR>
    <FOO>World Hello</FOO>

Add new comment

The content of this field is kept private and will not be shown publicly.


  • Lines and paragraphs break automatically.
  • You can caption images (data-caption="Text"), but also videos, blockquotes, and so on.
  • Web page addresses and email addresses turn into links automatically.
  • You can enable syntax highlighting of source code with the following tags: <code>, <blockcode>, <bash>, <cpp>, <css>, <html5>, <java>, <javascript>, <php>, <sql>, <xml>. The supported tag styles are: <foo>, [foo].
This question is for testing whether or not you are a human visitor and to prevent automated spam submissions.