Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Where's a DOM builder that uses the Builder Pattern to ... build DOMs?

2 views
Skip to first unread message

Phlip

unread,
Jan 4, 2010, 3:01:46 PM1/4/10
to
Not Hyp:

I hope I'm wrong, but seems that DOMBuilder, found among the various
xml.dom packages, cannot build DOM like this:

var html = DomBuilder.apply();

var form = html.FORM(
html.DIV(
html.INPUT({type : 'text', name : 'email'}),
html.INPUT({type : 'text', name : 'password'}),
html.INPUT({type : 'submit'}),
)
);

Do anyone know any good DOM builder packages that do build DOM good
like a DOM builder should?

--
Phlip
http://zeekland.zeroplayer.com/Uncle_Wiggilys_Travels/1

Stefan Behnel

unread,
Jan 5, 2010, 3:16:17 AM1/5/10
to
Phlip, 04.01.2010 21:01:

> Not Hyp:
>
> I hope I'm wrong, but seems that DOMBuilder, found among the various
> xml.dom packages, cannot build DOM like this:
>
> var html = DomBuilder.apply();
>
> var form = html.FORM(
> html.DIV(
> html.INPUT({type : 'text', name : 'email'}),
> html.INPUT({type : 'text', name : 'password'}),
> html.INPUT({type : 'submit'}),
> )
> );
>
> Do anyone know any good DOM builder packages that do build DOM good
> like a DOM builder should?

You might be looking for something like this:

http://codespeak.net/lxml/lxmlhtml.html#creating-html-with-the-e-factory

Note that there are tons of ways to generate HTML with Python. A quick web
search (or a quick read on PyPI or the Python Wiki) should get you started.

Stefan

Phlip

unread,
Jan 5, 2010, 12:00:01 PM1/5/10
to
On Jan 5, 12:16 am, Stefan Behnel <stefan...@behnel.de> wrote:

> Note that there are tons of ways to generate HTML with Python.

Forgot to note - I'm generating schematic XML, and I'm trying to find
a way better than the Django template I started with!

Stefan Behnel

unread,
Jan 7, 2010, 8:36:49 AM1/7/10
to
Phlip, 05.01.2010 18:00:

Well, then note that there are tons of ways to generate XML with Python,
including the one I pointed you to.

Stefan

Phlip

unread,
Jan 7, 2010, 11:44:25 AM1/7/10
to
On Jan 7, 5:36 am, Stefan Behnel <stefan...@behnel.de> wrote:

> Well, then note that there are tons of ways to generate XML with Python,
> including the one I pointed you to.

from lxml.html import builder as E
xml = E.foo()

All I want is "<foo/>", but I get "AttributeError: 'module' object has
no attribute 'foo'".

A peek at dir(E) shows it only has HTML tags, all hard coded.

So how to get it to generate any random XML tag my clients think of?

I will write this myself with __getattr__ etc, if I can't find it,
because the permissive & expressive builder pattern I'm after would be
very ... permissive & expressive.

All I want is a library that reads my mind!!! Is that too much to
ask??? (Unless if the library insists on throwing a NullMind
exception, on principle...)

--
Phlip
http://twitter.com/Pen_Bird

Stefan Behnel

unread,
Jan 13, 2010, 7:48:15 AM1/13/10
to
Phlip, 07.01.2010 17:44:

> On Jan 7, 5:36 am, Stefan Behnel <stefan...@behnel.de> wrote:
>
>> Well, then note that there are tons of ways to generate XML with Python,
>> including the one I pointed you to.
>
> from lxml.html import builder as E
> xml = E.foo()
>
> All I want is "<foo/>", but I get "AttributeError: 'module' object has
> no attribute 'foo'".
>
> A peek at dir(E) shows it only has HTML tags, all hard coded.

Note how you imported 'E' from a package called 'lxml.html'. The last part
of that package name gives a hint on what it specialises in.


> So how to get it to generate any random XML tag my clients think of?

Have you thought of taking a look at the tutorial?

http://codespeak.net/lxml/tutorial.html#the-e-factory

Stefan

0 new messages