By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
457,759 Members | 1,255 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 457,759 IT Pros & Developers. It's quick & easy.

lxml and SimpleXMLWriter

P: n/a
I am new to lxml. I am interested to know the equivalent code using
lxml (http://cheeseshop.python.org/pypi/lxml/1.1alpha). The code is
taken from http://effbot.org/zone/xml-writer.htm

from elementtree.SimpleXMLWriter import XMLWriter
import sys

w = XMLWriter(sys.stdout)

html = w.start("html")

w.start("head")
w.element("title", "my document")
w.element("meta", name="generator", value="my application 1.0")
w.end()

w.start("body")
w.element("h1", "this is a heading")
w.element("p", "this is a paragraph")

w.start("p")
w.data("this is ")
w.element("b", "bold")
w.data(" and ")
w.element("i", "italic")
w.data(".")
w.end("p")

w.close(html)

Best Regards,
Srijit

Jul 1 '06 #1
Share this Question
Share on Google+
2 Replies


P: n/a
Srijit Kumar Bhadra wrote:
I am new to lxml. I am interested to know the equivalent code using
lxml (http://cheeseshop.python.org/pypi/lxml/1.1alpha). The code is
taken from http://effbot.org/zone/xml-writer.htm


the lxml library implements the ElementTree module API (with
extensions), not the other parts of the ET library.

any reason you cannot just use the ET version ?

</F>

Jul 1 '06 #2

P: n/a
Srijit Kumar Bhadra wrote:
I am new to lxml. I am interested to know the equivalent code using
lxml (http://cheeseshop.python.org/pypi/lxml/1.1alpha). The code is
taken from http://effbot.org/zone/xml-writer.htm

from elementtree.SimpleXMLWriter import XMLWriter
import sys

w = XMLWriter(sys.stdout)

html = w.start("html")
[snip]

Note that the SimpleXMLWriter is in no way related to the ElementTree
implementation. Feel free to copy the module from the elementtree package and
use it with lxml.

Stefan
Jul 6 '06 #3

This discussion thread is closed

Replies have been disabled for this discussion.