Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #2577 > unrolled thread

XML header with lxml

Started byJabba Laci <jabba.laci@gmail.com>
First post2011-04-04 12:54 -0400
Last post2011-04-05 10:17 +0200
Articles 3 — 3 participants

Back to article view | Back to comp.lang.python


Contents

  XML header with lxml Jabba Laci <jabba.laci@gmail.com> - 2011-04-04 12:54 -0400
    Re: XML header with lxml Chroma Key <chroma@key.invalid> - 2011-04-04 21:49 +0200
      Re: XML header with lxml Stefan Behnel <stefan_ml@behnel.de> - 2011-04-05 10:17 +0200

#2577 — XML header with lxml

FromJabba Laci <jabba.laci@gmail.com>
Date2011-04-04 12:54 -0400
SubjectXML header with lxml
Message-ID<mailman.10.1301936101.9059.python-list@python.org>
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

[toc] | [next] | [standalone]


#2589

FromChroma Key <chroma@key.invalid>
Date2011-04-04 21:49 +0200
Message-ID<ind7bs$o4g$1@speranza.aioe.org>
In reply to#2577
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().

-- 
C-K

[toc] | [prev] | [next] | [standalone]


#2638

FromStefan Behnel <stefan_ml@behnel.de>
Date2011-04-05 10:17 +0200
Message-ID<mailman.37.1301991608.9059.python-list@python.org>
In reply to#2589
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

[toc] | [prev] | [standalone]


Back to top | Article view | comp.lang.python


csiph-web