StringOutput creates strings of XML.
Usage Example:
>>> xml_output = StringOutput(check_well_formedness=True)
>>> from ecoxipy import MarkupBuilder
>>> b = MarkupBuilder(xml_output)
>>> xml = b[:'section'] (
... b.section(
... b.p('Hello World!'),
... None,
... b.p(u'äöüß'),
... b.p(b & '<&>'),
... b(
... '<raw/>text', b.br,
... (str(i) for i in range(3)), (str(i) for i in range(3, 6))
... ),
... b | '<This is a comment!>',
... b['pi-target':'<PI content>'],
... b['pi-without-content':],
... attr='\'"<&>'
... )
... )
>>> xml == u"""<?xml version="1.0"?>\n<!DOCTYPE section><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>"""
True
>>> from ecoxipy import XMLWellFormednessException
>>> def catch_not_well_formed(method, *args):
... try:
... return getattr(xml_output, method)(*args)
... except XMLWellFormednessException as e:
... print(e)
>>> t = catch_not_well_formed(u'document', u'1nvalid-xml-name', None, None, [], True, u'UTF-8')
The value "1nvalid-xml-name" is not a valid XML name.
>>> t = catch_not_well_formed(u'document', u'html', u'"', None, [], True, u'UTF-8')
The value "\"" is not a valid document type public ID.
>>> t = catch_not_well_formed(u'document', u'html', None, u'"\'', [], True, u'UTF-8')
The value "\"'" is not a valid document type system ID.
>>> t = catch_not_well_formed(u'element', u'1nvalid-xml-name', [], {})
The value "1nvalid-xml-name" is not a valid XML name.
>>> t = catch_not_well_formed(u'element', u't', [], {u'1nvalid-xml-name': u'content'})
The value "1nvalid-xml-name" is not a valid XML name.
>>> t = catch_not_well_formed(u'processing_instruction', u'1nvalid-xml-name', None)
The value "1nvalid-xml-name" is not a valid XML processing instruction target.
>>> t = catch_not_well_formed(u'processing_instruction', u'target', u'invalid PI content ?>')
The value "invalid PI content ?>" is not a valid XML processing instruction content because it contains "?>".
>>> t = catch_not_well_formed(u'comment', u'invalid XML comment --')
The value "invalid XML comment --" is not a valid XML comment because it contains "--".
An ecoxipy.Output implementation which creates XML as strings.
Parameters: |
|
---|
Tests if an object is a XMLFragment instance.
Returns: | True for instances having XMLFragment as their class, False otherwise. |
---|
Creates an element string.
Returns: | The element created. |
---|---|
Return type: | XMLFragment |
Raises ecoxipy.XMLWellFormednessException: | |
If check_well_formedness is True and the name is not a valid XML name. |
Creates text string.
Returns: | The created text. |
---|---|
Return type: | XMLFragment |
Creates a comment string.
Returns: | The created comment. |
---|---|
Return type: | XMLFragment |
Raises ecoxipy.XMLWellFormednessException: | |
If check_well_formedness is True and content is not valid. |
Creates a processing instruction string.
Returns: | The created processing instruction. |
---|---|
Return type: | XMLFragment |
Raises ecoxipy.XMLWellFormednessException: | |
If check_well_formedness is True and either the target or the content are not valid. |
Creates a XML document.
Returns: | The created document. |
---|---|
Return type: | XMLDocument |
Raises ecoxipy.XMLWellFormednessException: | |
If check_well_formedness is True and the document type’s document element name is not a valid XML name, doctype_publicid is not a valid public ID or doctype_systemid is not a valid system ID. |
Return a XML fragment created from the children.
Return type: | XMLFragment |
---|
An XML Unicode string created by StringOutput.
An Unicode string representing a XML document created by StringOutput.