def as_xml(self, tag=None): """ Return an XML element representing ``self``. The element has tag ``tag``, or if that is omitted (or ``None``), the ``xml_default_tag`` attribute of ``self``'s class. """ tag = tag or self.xml_default_tag instance_td = Instance(self.__class__) # TODO: Cache this t.d. in class? return instance_td.xml_element(self, tag, [tag])
def serialize(obj, tag): """ Entry point function to serialize a Python object to an XML element. :param obj: Python object to serialize :type obj: instance of class having ``xml_descriptor`` attribute :return: XML element, as instance of :class:`etree.Element`. """ instance_td = Instance(obj.__class__) return instance_td.xml_element(obj, tag)