ETreeOutput creates xml.etree.ElementTree structures.
Usage Example:
>>> from xml.dom.minidom import getDOMImplementation
>>> etree_output = ETreeOutput()
>>> from ecoxipy import MarkupBuilder
>>> b = MarkupBuilder(etree_output)
>>> xml_doc = b[:'section':True] (
... b.section(
... b.p(b & 'Hello World!'),
... None,
... b(u'<p>äöüß</p>'),
... b.p('<&>'),
... b(
... '<raw/>text', b.br,
... (i for i in range(3)), (i for i in range(3, 6))
... ),
... b | '<This is a comment!>',
... b['pi-target':'<PI content>'],
... b['pi-without-content':],
... attr='\'"<&>'
... )
... )
>>> from io import BytesIO
>>> bytes_io = BytesIO()
>>> xml_doc.write(bytes_io, 'utf-8', True)
>>> document_string = u"""<?xml version='1.0' encoding='utf-8'?>\n<section attr="'"<&>"><p>Hello World!</p><p>äöüß</p><p><&></p><raw />text<br />012345<!--<This is a comment!>--><?pi-target <PI content>?><?pi-without-content?></section>"""
>>> bytes_io.getvalue() == document_string.encode('UTF-8')
True
An Output implementation which creates xml.etree.ElementTree structures.
Parameters: | element_factory – A xml.etree.ElementTree-compatible factory. If this is None xml.etree.ElementTree is used. |
---|
Tests if an object is a etree object by calling iselement() of the element factory.
Returns: | True for compatible xml.etree.ElementTree objects, False otherwise. |
---|
Creates an xml.etree.ElementTree.ElementTree-compatible object using the factory.
As xml.etree.ElementTree lacks support for document type declarations, the doctype_* parameters are ignored. Element tree wrappers do not allow specification of the output encoding and of the XML declaration, so encoding and omit_xml_declaration are also ignored. As element trees only allow one root element, the length of children must be zero or one, otherwise a ValueError is raised.