Dynamically generate a new :class:`XmlObjectForm` class using the
    specified :class:`eulxml.xmlmap.XmlObject` class.

    Based on django's modelform_factory.

def xmlobjectform_factory(model, form=XmlObjectForm, fields=None, exclude=None,
                          widgets=None, max_num=None, label=None, can_delete=True,
                          extra=None, can_order=False):
    """Dynamically generate a new :class:`XmlObjectForm` class using the
    specified :class:`eulxml.xmlmap.XmlObject` class.

    Based on django's modelform_factory.
    """

    attrs = {'model': model}
    if fields is not None:
        attrs['fields'] = fields
    if exclude is not None:
        attrs['exclude'] = exclude
    if widgets is not None:
        attrs['widgets'] = widgets
    if max_num is not None:
        attrs['max_num'] = max_num
    if extra is not None:
        attrs['extra'] = extra
    if can_delete is not None:
        attrs['can_delete'] = can_delete
    if can_order is not None:
        attrs['can_order'] = can_order

    # If parent form class already has an inner Meta, the Meta we're
    # creating needs to inherit from the parent's inner meta.
    parent = (object,)
    if hasattr(form, 'Meta'):
        parent = (form.Meta, object)
    Meta = type(str('Meta'), parent, attrs)

    # Give this new form class a reasonable name.
    class_name = model.__name__ + str('XmlObjectForm')

    # Class attributes for the new form class.
    form_class_attrs = {
        'Meta': Meta,
        # django has a callback formfield here; do we need that?
        # label for a subform/formset
        'form_label': label,
    }

    return XmlObjectFormType(class_name, (form,), form_class_attrs)