def xmlobject_to_dict(instance, fields=None, exclude=None, prefix='<STR_LIT>'):
data = {}<EOL>if prefix:<EOL><INDENT>prefix = '<STR_LIT>' % prefix<EOL><DEDENT>else:<EOL><INDENT>prefix = '<STR_LIT>'<EOL><DEDENT>for name, field in six.iteritems(instance._fields):<EOL><INDENT>if fields and not name in fields:<EOL><INDENT>continue<EOL><DEDENT>if exclude and name in exclude:<EOL><INDENT>continue<EOL><DEDENT>if isinstance(field, xmlmap.fields.NodeField):<EOL><INDENT>nodefield = getattr(instance, name)<EOL>if nodefield is not None:<EOL><INDENT>subprefix = '<STR_LIT>' % (prefix, name)<EOL>node_data = xmlobject_to_dict(nodefield, prefix=subprefix)<EOL>data.update(node_data)   <EOL><DEDENT><DEDENT>if isinstance(field, xmlmap.fields.NodeListField):<EOL><INDENT>for i, child in enumerate(getattr(instance, name)):<EOL><INDENT>subprefix = '<STR_LIT>' % (prefix, name, i)<EOL>node_data = xmlobject_to_dict(child, prefix=subprefix)<EOL>data.update(node_data)   <EOL><DEDENT><DEDENT>else:<EOL><INDENT>data[prefix + name] = getattr(instance, name)<EOL><DEDENT><DEDENT>return data<EOL>
Generate a dictionary based on the data in an XmlObject instance to pass as
a Form's ``initial`` keyword argument.

:param instance: instance of :class:`~eulxml.xmlmap.XmlObject`
:param fields: optional list of fields - if specified, only the named fields
        will be included in the data returned
:param exclude: optional list of fields to exclude from the data