| Home | Trees | Indices | Help |
|
|---|
object --+ | ElementMaker
ElementMaker(self, namespace=None, nsmap=None, annotate=True, makeelement=None)
An ElementMaker that can be used for constructing trees.
Example:
>>> M = ElementMaker(annotate=False)
>>> attributes = {'class': 'par'}
>>> html = M.html( M.body( M.p('hello', attributes, M.br, 'objectify', style="font-weight: bold") ) )
>>> from lxml.etree import tostring
>>> print(tostring(html, method='html').decode('ascii'))
<html><body><p style="font-weight: bold" class="par">hello<br>objectify</p></body></html>
To create tags that are not valid Python identifiers, call the factory directly and pass the tag name as first argument:
>>> root = M('tricky-tag', 'some text')
>>> print(root.tag)
tricky-tag
>>> print(root.text)
some text
Note that this module has a predefined ElementMaker instance called E.
Inherited from object:
__delattr__,
__format__,
__hash__,
__reduce__,
__reduce_ex__,
__repr__,
__setattr__,
__sizeof__,
__str__,
__subclasshook__
Inherited from object:
__class__
| Home | Trees | Indices | Help |
|
|---|