from builder import ElementMaker, E, ET # some common inline elements A = E.a I = E.i B = E.b def CLASS(*args): # class is a reserved word, so we use a helper for this attribute return {"class": " ".join(args)} page = ( E.html( E.head( E.title("This is a sample document") ), E.body( E.h1("Hello!", CLASS("title")), E.p("This is a paragraph with ", B("bold"), "text in it!"), E.p("This is another paragraph, with ", A("link", href="http://www.python.org"), "."), E.p("Here are some reservered characters: ."), ET.XML("

And finally, here's an embedded XHTML fragment.

"), ) ) ) import indent indent.indent(page) print ET.tostring(page) from datetime import datetime, timedelta, tzinfo class UTC(tzinfo): def utcoffset(self, dt): return timedelta(0) def tzname(self, dt): return "UTC" def dst(self, dt): return timedelta(0) RSS = ElementMaker(typemap={ datetime: lambda e, i: i.strftime("%a, %d %b %Y %H:%M:%S %z") }) item = RSS.item( RSS.title("E=RSS squared"), RSS.link("http://effbot.org"), RSS.description("Yet another E-related example"), RSS.pubDate(datetime.now(UTC())) ) indent.indent(item) print ET.tostring(item)