Blog Archive for February 3, 2011

Pretty Print XML in Python

February 3, 2011

The xmlpp library can be used to convert xml into a pretty format. Unfortunately, it still puts text nodes on their own lines:

<tag>
  <tag>
    Text
  </tag>
</tag>

when what we really want is:

<tag>
  <tag>Text</tag>
</tag>

Older versions of xmlpp also didn't support namespace prefixes - the …