XML header with lxml

Stefan Behnel stefan_ml at behnel.de
Tue Apr 5 10:17:34 CEST 2011


Chroma Key, 04.04.2011 21:49:
> On 2011-04-04 18:54:40 +0200, Jabba Laci said:
>
>> I want to construct an XML file with lxml but I don't find how to add
>> the '<?xml version="1.0"?>' header.
>>
>> from lxml import etree as ET
>>
>> html = ET.Element("html")
>> print ET.tostring(html)
>
> Add the "xml_declaration=True" as an argument of etree.tostring().

Ah, yes. That's the right way to do it (if you need it).

Stefan




More information about the Python-list mailing list