Package xmlschema_acue :: Module converters :: Class ParkerConverter

Class ParkerConverter

source code


XML Schema based converter class for Parker convention.

ref: http://wiki.open311.org/JSON_and_XML_Conversion/#the-parker-convention

:param namespaces: Map from namespace prefixes to URI. :param dict_class: Dictionary class to use for decoded data. Default is `dict` for Python 3.6+ or `OrderedDict` for previous versions. :param list_class: List class to use for decoded data. Default is `list`. :param preserve_root: If `True` the root element will be preserved. For default the Parker convention remove the document root element, returning only the value.

Instance Methods

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, preserve_root=False, **kwargs)
(Constructor)

source code 
Decorators:
Overrides: namespaces.NamespaceMapper.__init__

__setattr__(self, name, value)

source code 
Decorators:
Overrides: XMLSchemaConverter.__setattr__

lossless(self)

source code 

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

Decorators:
  • @property
Overrides: XMLSchemaConverter.lossless
(inherited documentation)

copy(self, **kwargs)

source code 
Decorators:
Overrides: XMLSchemaConverter.copy

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:
Overrides: XMLSchemaConverter.element_decode
(inherited documentation)

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:
Overrides: XMLSchemaConverter.element_encode
(inherited documentation)

default_namespace(self)

source code 
Decorators:
  • @property

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:

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: