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

Discussion in 'Python' started by Phlip, Jan 4, 2010.

  1. Phlip

    Phlip Guest

    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
    Phlip, Jan 4, 2010
    #1
    1. Advertising

  2. 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
    Stefan Behnel, Jan 5, 2010
    #2
    1. Advertising

  3. Phlip

    Phlip Guest

    On Jan 5, 12:16 am, Stefan Behnel <> 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!
    Phlip, Jan 5, 2010
    #3
  4. Phlip, 05.01.2010 18:00:
    > On Jan 5, 12:16 am, Stefan Behnel <> 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!


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

    Stefan
    Stefan Behnel, Jan 7, 2010
    #4
  5. Phlip

    Phlip Guest

    On Jan 7, 5:36 am, Stefan Behnel <> 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
    Phlip, Jan 7, 2010
    #5
  6. Phlip, 07.01.2010 17:44:
    > On Jan 7, 5:36 am, Stefan Behnel <> 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
    Stefan Behnel, Jan 13, 2010
    #6
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. qazmlp
    Replies:
    2
    Views:
    362
    iksrazal
    Jan 31, 2004
  2. qazmlp
    Replies:
    2
    Views:
    512
    iksrazal
    Jan 31, 2004
  3. Verne
    Replies:
    6
    Views:
    1,666
    Jonathan Turkanis
    Nov 8, 2004
  4. Jason

    Builder Pattern

    Jason, Jan 29, 2006, in forum: Python
    Replies:
    4
    Views:
    693
    Peter Otten
    Feb 2, 2006
  5. Mike
    Replies:
    2
    Views:
    330
    Stuart Golodetz
    May 22, 2006
Loading...

Share This Page