Fixing the XML batteries

Serhiy Storchaka storchaka at gmail.com
Tue Dec 13 07:18:26 EST 2011


09.12.11 17:09, Dirkjan Ochtman wrote:
> On Fri, Dec 9, 2011 at 09:02, Stefan Behnel<stefan_ml at behnel.de>  wrote:
> An at least somewhat informed +1 from me. The ElementTree API is a
> very good way to deal with XML from Python, and it deserves to be
> promoted over the included alternatives.
>
> Let's deprecate the NiCad batteries and try to guide users toward the
> Li-Ion ones.

I use xml.dom.minidom for XML canonization and convertion:

doc = xml.dom.minidom.parse( io.BytesIO( data0 ) )
encoding = forceEncoding or doc.encoding or str( 'UTF-8' )
writer = io.BytesIO()
writer = codecs.getwriter( encoding )( writer,  'xmlcharrefreplace' )
doc.writexml( writer, encoding = encoding )
data = writer.getvalue()

How to do this with xml.etree.ElementTree?




More information about the Python-list mailing list