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


Groups > comp.lang.python > #2637

Re: XML header with lxml

From Stefan Behnel <stefan_ml@behnel.de>
Subject Re: XML header with lxml
Date 2011-04-05 10:16 +0200
References <BANLkTin9SbjxtJ-UO9ZSvRy_7rh9b3Hi+g@mail.gmail.com>
Newsgroups comp.lang.python
Message-ID <mailman.36.1301991392.9059.python-list@python.org> (permalink)

Show all headers | View raw


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

Back to comp.lang.python | Previous | Next | Find similar | Unroll thread


Thread

Re: XML header with lxml Stefan Behnel <stefan_ml@behnel.de> - 2011-04-05 10:16 +0200

csiph-web