Jabba Laci, 04.04.2011 18:54:
I want to construct an XML file with lxml but I don't find how to add
the '<?xml version="1.0"?>' header.

This is not required. According to the XML spec, the default is:

  <?xml version="1.0" encoding="utf-8" standalone="false"?>

So, unless you diverge from these values, you do not need an XML declaration in your file. If you want to output the declaration anyway, you can simply prepend it to the string or write it into the output file before serialising.


from lxml import etree as ET

html = ET.Element("html")
print ET.tostring(html)

simply prints
<html/>

I imagine you are aware that HTML isn't XML.

Stefan

--
http://mail.python.org/mailman/listinfo/python-list

Reply via email to