Output XML buffer?

Stefan Behnel stefan.behnel-n05pAM at web.de
Tue Jun 26 07:07:52 CEST 2007


Jan Danielsson wrote:
>    I'm using ElementTree to create an XHTML page (mod_python, blah,
> blah, blah). When I use ElementTree.tostring(root) to create a buffer
> which I want to return to the client, it doesn't include the XML prolog

As Martin told you, this is spec-compliant behaviour. Still, ElementTree 1.3
is expected to add a keyword argument "xml_declaration" in tostring() that
will let you override the default behaviour. lxml.etree already implements
that, BTW.

http://codespeak.net/lxml


>    I could simply prefix the tostring output with a string containing my
> "<?xml ...>" schtick. But let's, for the sake of argument, say that I
> trust a library more to generate it for me, rather than hand coding it
> myself (not entirely true, but let's assume that is the case).

Some people propose just that if you really *want* a declaration. No need to
have it, though, as ET will create well-formed XML anyway.

Stefan



More information about the Python-list mailing list