formatted xml output from ElementTree inconsistency

Kent Johnson kent37 at
Fri Jun 24 12:46:37 CEST 2005

Matthew Thorley wrote:
> Greetings, perhaps someone can explain this. I get to different styles 
> of formatting for xmla and xmlb when I do the following:
> <snip>
> Is that because the some_file.xml is already nicely formatted? I thought 
> that the formatting was ignored when creating new elements.

ElementTree is preserving the whitespace of the original.
> Is their a function to 'pretty print' an element? 

AFAIK this is not supported in ElementTree. I hacked my own by modifying ElementTree._write(); it wasn't too hard to make a version that suited my purposes.


More information about the Python-list mailing list