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

P

Phlip

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?
 
S

Stefan Behnel

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
 
P

Phlip

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!
 
S

Stefan Behnel

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

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

Stefan
 
P

Phlip

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...)
 
S

Stefan Behnel

Phlip, 07.01.2010 17:44:
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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,756
Messages
2,569,535
Members
45,008
Latest member
obedient dusk

Latest Threads

Top