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


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

Re: XML header with lxml

Started byStefan Behnel <stefan_ml@behnel.de>
First post2011-04-05 10:16 +0200
Last post2011-04-05 10:16 +0200
Articles 1 — 1 participant

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

This discussion starts older than the indexed window; earlier articles aren't shown. The article labeled Started by below is the oldest one visible, not the original post.


Contents

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

#2637 — Re: XML header with lxml

FromStefan Behnel <stefan_ml@behnel.de>
Date2011-04-05 10:16 +0200
SubjectRe: XML header with lxml
Message-ID<mailman.36.1301991392.9059.python-list@python.org>
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

[toc] | [standalone]


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


csiph-web