XML header with lxml

J

Jabba Laci

Hi,

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)

simply prints
<html/>

Thanks,

Laszlo
 
C

Chroma Key

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().
 
S

Stefan Behnel

Chroma Key, 04.04.2011 21:49:
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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,981
Messages
2,570,187
Members
46,731
Latest member
MarcyGipso

Latest Threads

Top