import lxml.etree
def parse_xml(xml):
    if not len(xml):
        return {xml.tag: xml.text}
    result = {}
    for child in xml:
        child_result = parse_xml(child)
        if child.tag != 'object':
            result[child.tag] = child_result[child.tag]
        else:
            if child.tag not in result:
                result[child.tag] = []
            result[child.tag].append(child_result[child.tag])
    return {xml.tag: result}

def read_xml(path):
    annotation_xml = lxml.etree.fromstring(open(path).read())
    annotation = parse_xml(annotation_xml)['annotation']
    return annotation
import lxml.etree
def parse_xml(xml):
    if not len(xml):
        return {xml.tag: xml.text}
    result = {}
    for child in xml:
        child_result = parse_xml(child)
        if child.tag != 'object':
            result[child.tag] = child_result[child.tag]
        else:
            if child.tag not in result:
                result[child.tag] = []
            result[child.tag].append(child_result[child.tag])
    return {xml.tag: result}

def read_xml(path):
    annotation_xml = lxml.etree.fromstring(open(path).read())
    annotation = parse_xml(annotation_xml)['annotation']
    return annotation