ANN: XML builder for Python

Walter Dörwald walter at livinglogic.de
Thu Jul 3 07:37:23 EDT 2008


Stefan Behnel wrote:
> Stefan Behnel wrote:
>> Jonas Galvez wrote:
>>> Not sure if it's been done before, but still...
>> Obviously ;)
>>
>> http://codespeak.net/lxml/tutorial.html#the-e-factory
>>
>> ... and tons of other tools that generate XML, check PyPI.
> 
> Although it might be the first time I see the with statement "misused" for
> this. :)

XIST has been using with blocks since version 3.0.

Take a look at:
http://www.livinglogic.de/Python/xist/Examples.html


from __future__ import with_statement

from ll.xist import xsc
from ll.xist.ns import html, xml, meta

with xsc.Frag() as node:
    +xml.XML()
    +html.DocTypeXHTML10transitional()
    with html.html():
       with html.head():
          +meta.contenttype()
          +html.title("Example page")
       with html.body():
          +html.h1("Welcome to the example page")
          with html.p():
             +xsc.Text("This example page has a link to the ")
             +html.a("Python home page", href="http://www.python.org/")
             +xsc.Text(".")

print node.conv().bytes(encoding="us-ascii")

Servus,
    Walter



More information about the Python-list mailing list