+ return XmlElement(self.element.getparent(), self.namespaces)
+
+ def get_instance(self, instance_class=None, fields=None):
+ """
+ Returns an instance (dict) of this xml element. The instance
+ holds a reference to this xml element.
+ """
+ if fields is None:
+ fields = []
+ if not instance_class:
+ instance_class = Element
+ if not fields and hasattr(instance_class, 'fields'):
+ fields = instance_class.fields
+
+ if not fields:
+ instance = instance_class(self.attrib, self)
+ else:
+ instance = instance_class({}, self)
+ for field in fields:
+ if field in self.attrib:
+ instance[field] = self.attrib[field]
+ return instance
+
+ def add_instance(self, name, instance, fields=None):
+ """
+ Adds the specifed instance(s) as a child element of this xml
+ element.
+ """
+ if fields is None:
+ fields = []
+ if not fields and hasattr(instance, 'keys'):
+ fields = instance.keys()
+ elem = self.add_element(name)
+ for field in fields:
+ if field in instance and instance[field]:
+ elem.set(field, unicode(instance[field]))
+ return elem