<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
 def update_instance(self):
 """Save bound form data into the XmlObject model instance and return the updated instance."""


        # NOTE: django model form has a save method - not applicable here,
        # since an XmlObject by itself is not expected to have a save method
        # (only likely to be saved in context of a fedora or exist object)

        if hasattr(self, 'cleaned_data'):   # possible to have an empty object/no data

            opts = self._meta

            # NOTE: _fields doesn't seem to order, which is
            # problematic for some xml (e.g., where order matters for validity)

            # use field order as declared in the form for update order
            # when possible.
            # (NOTE: this could be problematic also, since display order may
            # not always be the same as schema order)
            fields_in_order = []
            if hasattr(self.Meta, 'fields'):
                fields_in_order.extend(self.Meta.fields)
                fields_in_order.extend([name for name in six.iterkeys(self.instance._fields)
                                        if name in self.Meta.fields])
            else:
                fields_in_order = self.instance._fields.keys()

            for name in fields_in_order:
            # for name in self.instance._fields.iterkeys():
            # for name in self.declared_fields.iterkeys():
                if opts.fields and name not in opts.parsed_fields.fields:
                    continue
                if opts.exclude and name in opts.parsed_exclude.fields:
                    continue
                if name in self.cleaned_data:
                    # special case: we don't want empty attributes and elements
                    # for fields which returned no data from the form
                    # converting '' to None and letting XmlObject handle
                    if self.cleaned_data[name] == '':
                        self.cleaned_data[name] = None
                    setattr(self.instance, name, self.cleaned_data[name])

            # update sub-model portions via any subforms
            for name, subform in six.iteritems(self.subforms):
                self._update_subinstance(name, subform)
            for formset in six.itervalues(self.formsets):
                formset.update_instance()
        return self.instance