Re: Writing XML files with ElementTree

Kent Tenney <[email protected]>
Newsgroups gmane.comp.python.xml
Message-ID <[email protected]>
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_
but 
http://www.w3.org/TR/2006/REC-xml-20060816/#sec-prolog-dtd
says
[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

:-]

Thanks,
Kent

(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.
> 
> </F> 
> 
> _______________________________________________
> XML-SIG maillist  -  XML-SIG <at> python.org
> http://mail.python.org/mailman/listinfo/xml-sig
> 
> 




_______________________________________________
XML-SIG maillist  -  [email protected]
http://mail.python.org/mailman/listinfo/xml-sig
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.