lxml.objectify.ElementMaker
Class ElementMaker
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.
|
|
|
|
|
|
|
__init__(self,
namespace=None,
nsmap=None,
annotate=True,
makeelement=None)
x.__init__(...) initializes x; see help(type(x)) for signature |
|
|
a new object with type S, a subtype of T
|
|
Inherited from object :
__delattr__ ,
__format__ ,
__hash__ ,
__reduce__ ,
__reduce_ex__ ,
__repr__ ,
__setattr__ ,
__sizeof__ ,
__str__ ,
__subclasshook__
|
Inherited from object :
__class__
|
x.__getattribute__('name') <==> x.name
- Overrides:
object.__getattribute__
|
__init__(self,
namespace=None,
nsmap=None,
annotate=True,
makeelement=None)
(Constructor)
|
|
x.__init__(...) initializes x; see help(type(x)) for signature
- Overrides:
object.__init__
|
- Returns: a new object with type S, a subtype of T
- Overrides:
object.__new__
|