What is the best way (or are the various ways) to pretty print XML in Python?
Here's my (hacky?) solution to get around the ugly text node problem.
uglyXml = doc.toprettyxml(indent=' ')
text_re = re.compile('>\n\s+([^<>\s].*?)\n\s+', re.DOTALL)
prettyXml = text_re.sub('>\g<1>', uglyXml)
print prettyXml
The above code will produce:
1
Add Visual Studio 2005 and 2008 solution files
We need Visual Studio 2005/2008 project files for Windows.
Instead of this:
1
Add Visual Studio 2005 and 2008 solution files
We need Visual Studio 2005/2008 project files for Windows.
Disclaimer: There are probably some limitations.