ecoxipy.pyxom.output - Building PyXOM Structures

PyXOMOutput creates structures consisting of ecoxipy.pyxom data.

Examples

Creating a document and retrieving the byte string:

>>> from ecoxipy import MarkupBuilder
>>> b = MarkupBuilder()
>>> document = b[:'section':True] (
...     b.article(
...         b.h1(
...             b & '<Example>', # Explicitly insert text
...             data='to quote: <&>"\''
...         ),
...         b.p(
...             {'umlaut-attribute': u'äöüß'},
...             'Hello', b.em(' World', count=1), '!'
...         ),
...         None,
...         b.div(
...             # Insert elements with special names using subscripts:
...             b['data-element'](u'äöüß <&>'),
...             # Import content by calling the builder:
...             b(
...                 '<p attr="value">raw content</p>Some Text',
...                 # Create an element without calling the creating method:
...                 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':],
...         lang='en'
...     )
... )
>>> document_string = u"""<!DOCTYPE section><article lang="en"><h1 data="to quote: &lt;&amp;&gt;&quot;'">&lt;Example&gt;</h1><p umlaut-attribute="äöüß">Hello<em count="1"> World</em>!</p><div><data-element>äöüß &lt;&amp;&gt;</data-element><p attr="value">raw content</p>Some Text<br/>012345</div><!--<This is a comment!>--><?pi-target <PI content>?><?pi-without-content?></article>"""
>>> bytes(document) == document_string.encode('UTF-8')
True

For more examples see ecoxipy.pyxom.

Output Implementation

class ecoxipy.pyxom.output.PyXOMOutput(check_well_formedness=False)[source]

An Output implementation which creates ecoxipy.pyxom.XMLNode instances and Unicode string instances.

Parameters:check_well_formedness (bool()) – The attribute check_well_formedness is determined by this value.
check_well_formedness[source]

If True the nodes will be checked for valid values.

static is_native_type(content)[source]

Tests if an object has the attribute _IS_PYXOM_NODE and that this is True.

Returns:True if the object has the attribute _IS_PYXOM_NODE being :const`True`, False otherwise.
element(name, children, attributes)[source]

Returns an ecoxipy.pyxom.Element.

Return type:ecoxipy.pyxom.Element
Raises ecoxipy.XMLWellFormednessException:
 If check_well_formedness is True and the name is not a valid XML name.
text(content)[source]

Creates a ecoxipy.pyxom.Text node.

Return type:ecoxipy.pyxom.Text
comment(content)[source]

Creates a ecoxipy.pyxom.Comment.

Return type:ecoxipy.pyxom.Comment
Raises ecoxipy.XMLWellFormednessException:
 If check_well_formedness is True and content is not valid.
processing_instruction(target, content)[source]

Creates a ecoxipy.pyxom.ProcessingInstruction.

Return type:ecoxipy.pyxom.ProcessingInstruction
Raises ecoxipy.XMLWellFormednessException:
 If check_well_formedness is True and either the target or the``content`` are not valid.
document(doctype_name, doctype_publicid, doctype_systemid, children, omit_xml_declaration, encoding)[source]

Creates a ecoxipy.pyxom.Document instance.

Return type:ecoxipy.pyxom.Document
Raises ecoxipy.XMLWellFormednessException:
 If check_well_formedness is True and doctype_name is not a valid XML name, doctype_publicid is not a valid public ID or doctype_systemid is not a valid system ID.