Output XML buffer?
"Martin v. Löwis"
martin at v.loewis.de
Mon Jun 25 23:38:01 CEST 2007
> 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
> (obvisouly, since tostring is merely traversing the tree from the node I
> supply to it.
Not at all obvious. It considered writing an XML prolog, but then
decided against it because the output encoding was UTF-8 or ASCII,
in which case the prolog can be safely omitted by the XML
> 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).
Did you mean to include some question? If you meant to ask "Can I make
it write an XML prolog, and if so, how?", then the anwser is:
use an output encoding different from utf-8 or us-ascii.
More information about the Python-list