XML Codec

Codec for serialising and de-serialising XML data. Supports both array and objects for mapping into resources or collections of resources.

XML Codec (output only)

Output a resource structure as XML

XML has a unique attribute in the form of the text. This is plain text that can be placed within a pair of tags.

To support this the XML codec includes a TextField, any TextField found on a resource will be exported (if multiple are defined they will all be exported into the one text block).

The TextField is for all intents and purposes just a StringField, other codecs will export any value as a String.

Methods

odin.codecs.xml_codec.dump(fp: TextIO, resource, line_ending: str = '')[source]

Dump a resource to a file like object. :param fp: File pointer or file like object. :param resource: Resource to dump :param line_ending: End of line character to apply

odin.codecs.xml_codec.dumps(resource, **kwargs)[source]

Dump a resource to a string.

Parameters:

resource – Resource to dump

Unsupported Fields

There is no direct representation for a odin.fields.DictField.

Example usage

Loading a resource from a file:

from odin.codecs import xml_codec

with open('my_resource.xml') as f:
    resource = xml_codec.load(f)

Saving a resource to a file:

from odin.codecs import xml_codec

with open('my_resource.xml', 'w') as f:
    xml_codec.dump(f, resource)