Package xmlschema_acue :: Module converters :: Class XMLSchemaConverter

Class XMLSchemaConverter

source code


Generic XML Schema based converter class. A converter is used to compose decoded XML data for an Element into a data structure and to build an Element from encoded data structure.

:param namespaces: map from namespace prefixes to URI. :param dict_class: dictionary class to use for decoded data. Default is `dict`. :param list_class: list class to use for decoded data. Default is `list`. :param text_key: is the key to apply to element's decoded text data. :param attr_prefix: controls the mapping of XML attributes, to the same name or with a prefix. If `None` the converter ignores attributes. :param cdata_prefix: is used for including and prefixing the CDATA parts of a mixed content, that are labeled with an integer instead of a string. CDATA parts are ignored if this argument is `None`. :param etree_element_class: the class that has to be used to create new XML elements, if not provided uses the ElementTree's Element class. :param indent: number of spaces for XML indentation (default is 4).

:ivar dict: dictionary class to use for decoded data. :ivar list: list class to use for decoded data. :ivar text_key: key for decoded Element text :ivar attr_prefix: prefix for attribute names :ivar cdata_prefix: prefix for character data parts :ivar etree_element_class: Element class to use :ivar indent: indentation to use for rebuilding XML trees

Instance Methods
 
__setattr__(self, name, value) source code
 
copy(self, **kwargs) source code

Inherited from namespaces.NamespaceMapper: __delitem__, __getitem__, __iter__, __len__, __setitem__, clear, map_qname, transfer, unmap_qname

Method Details

__init__(self, namespaces=None, dict_class=None, list_class=None, text_key='$', attr_prefix='@', cdata_prefix=None, etree_element_class=None, indent=4, **kwargs)
(Constructor)

source code 
Decorators:
Overrides: namespaces.NamespaceMapper.__init__

lossless(self)

source code 

The converter can ignore some kind of XML data during decoding.

Decorators:
  • @property

losslessly(self)

source code 

The format of decoded data is without loss of quality. Only losslessly formats can be always used to encode to an XML data that is strictly conformant to the schema.

Decorators:
  • @property

map_attributes(self, attributes)

source code 

Creates an iterator for converting decoded attributes to a data structure with appropriate prefixes. If the instance has a not-empty map of namespaces registers the mapped URIs and prefixes.

:param attributes: A sequence or an iterator of couples with the name of the attribute and the decoded value. Default is `None` (for `simpleType` elements, that don't have attributes).

Decorators:

map_content(self, content)

source code 

A generator function for converting decoded content to a data structure. If the instance has a not-empty map of namespaces registers the mapped URIs and prefixes.

:param content: A sequence or an iterator of tuples with the name of the element, the decoded value and the `XsdElement` instance associated.

Decorators:

etree_element(self, tag, text=None, children=None, attrib=None, level=0)

source code 

Builds an ElementTree's Element using arguments and the element class and the indent spacing stored in the converter instance.

:param tag: the Element tag string. :param text: the Element text. :param children: the list of Element children/subelements. :param attrib: a dictionary with Element attributes. :param level: the level related to the encoding process (0 means the root). :return: an instance of the Element class setted for the converter instance.

Decorators:

element_decode(self, data, xsd_element, level=0)

source code 

Converts a decoded element data to a data structure.

:param data: ElementData instance decoded from an Element node. :param xsd_element: the `XsdElement` associated to decoded the data. :param level: the level related to the decoding process (0 means the root). :return: a data structure containing the decoded data.

Decorators:

element_encode(self, obj, xsd_element, level=0)

source code 

Extracts XML decoded data from a data structure for encoding into an ElementTree.

:param obj: the decoded object. :param xsd_element: the `XsdElement` associated to the decoded data structure. :param level: the level related to the encoding process (0 means the root). :return: an ElementData instance.

Decorators:

default_namespace(self)

source code 
Decorators:
  • @property