def element_to_dict(element):
    """
    Convert an ElementTree element into a dictionary
    """

    # Dictionary to represent the element and its children
    elem_dict={}
    for child in element:
        # Separate the schema name from the tag name
        tagname=child.tag.split('}')[1]

        if child.text is not None:
            # If the child is a text object, use it as-is
            child_value=child.text
        else:
            # Child is an XML element, parse it
            child_value=element_to_dict(child)

        # Add child to the dictionary
        if tagname in elem_dict.keys():
            # Tag is already in the dictionary, make a list instead
            try:
                elem_dict[tagname].append(child_value)
            except AttributeError:
                # Existing key is a scalar, convert it to a list and add
                # the new value to the end
                elem_dict[tagname]=[elem_dict[tagname],child_value]
        else:
            elem_dict[tagname]=child_value
    return elem_dict