473,323 Members | 1,560 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,323 software developers and data experts.

lxml and SimpleXMLWriter

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
2 2473
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
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
by: Jan Dries | last post by:
I'm trying to find Windows binaries for lxml. The cheeseshop is supposed to have such binaries, but I can't find them. Does anyone know where I might find such binaries? Thanks, Jan
30
by: Chas Emerick | last post by:
I looked around for an ElementTree-specific mailing list, but found none -- my apologies if this is too broad a forum for this question. I've been using the lxml variant of the ElementTree API,...
1
by: peterbe | last post by:
I'll try to explain my problem with code. The problem is the output msg = u"Södertälje & Borås" # latin1 unicode string with a & from elementtree.SimpleXMLWriter import XMLWriter from...
1
by: Maxim Sloyko | last post by:
Hi All! I have a little problem with XML namespaces. In my application I have two XML processors, that process the same document, one after the other. The first one looks for nodes in 'ns1'...
0
by: Stefan Behnel | last post by:
Hi everyone, I'm very happy to announce the official release of lxml 2.0! http://codespeak.net/lxml/ http://pypi.python.org/pypi/lxml/2.0 ** What is lxml? """
7
by: Silfheed | last post by:
Heyas So first off I know that CDATA is generally hated and just shouldn't be done, but I'm simply required to parse it and spit it back out. Parsing is pretty easy with lxml, but it's the...
1
by: =?iso-8859-1?q?KLEIN_St=E9phane?= | last post by:
Hi, I'm on Ubuntu 8.04.1 I've installed lxml with easy_install lxml command. Now, when I load etree I've this error : $ python Python 2.5.2 (r252:60911, Apr 21 2008, 11:12:42)
0
by: =?iso-8859-1?q?KLEIN_St=E9phane?= | last post by:
Le Mon, 25 Aug 2008 13:50:50 +0000, KLEIN Stéphane a écrit : I've this bug only with lxml2, lxml 1.3.3 work very well. Regards, Stephane
1
by: Owen Zhang | last post by:
I am trying to build lxml package in SunOS 5.10. I got the following errors. Does anybody know why? $ python setup.py build Building lxml version 2.1. NOTE: Trying to build without Cython,...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.