[XML-SIG] Writing XML files with ElementTree
ktenney at gmail.com
Thu Mar 22 12:06:51 CET 2007
Fredrik Lundh <fredrik <at> pythonware.com> writes:
> Kent Tenney wrote:
> > write() says
> > elif encoding != "utf-8" and encoding != "us-ascii":
> > file.write("<?xml version='1.0' encoding='%s'?>\n" % encoding)
> > How do I get the declaration written if I want
> > encoding to be utf-8 ?
> since it's usually not needed
Surprises me, looks so _necessary_
[Definition: XML documents SHOULD begin with an
XML declaration which specifies the version of XML being used.]
I certainly don't do all I SHOULD
(the declaration is optional if the file's using
> UTF-8 or a compatible encoding), you have to add it yourself.
> the upcoming 1.3 release has a "xml_declaration" option that gives you
> more control over this. lxml.etree also implements that, iirc.
> XML-SIG maillist - XML-SIG <at> python.org
More information about the XML-SIG