On Thu, Jan 7, 2010 at 8:44 AM, Phlip <phlip2...@gmail.com> wrote:

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

If you want to generate random XML, don't use the HTML sub-module of lxml.
Its a specific sub-set of functionality for HTML only documents.

>>> from lxml.builder import ElementMaker
>>> from lxml import etree
>>> E = ElementMaker()
>>> html = E.html(
...     E.form(
...             E.input(type="text", name="email"),
...             E.input(type="text", name="blah")
...     )
... )
>>> etree.tostring(html)
'<html><form><input type="text" name="email"/><input type="text"
name="blah"/></form></html>'

HTH,

--S
-- 
http://mail.python.org/mailman/listinfo/python-list

Reply via email to