tag:sub_element_with_attrattribute:{'attr''complex'tag datasub_element_text tag:sub_element_only_attrattribute:{'attr_val''only_attr'tag data:none tag:recordattribute:{'name''rec_ 'tag datatag:sub_elementattribute:{tag datatag:detail attribute:{tag data:attribute tag:detail attribute:{tag data: tag:sub_element_with_attrattribute:{'attr''complex'tag datasub_element_text tag:sub_element_only_attrattribute:{'attr_val''only_attr'tag data:none the xml library provides very useful utilities exposed through the elementtree parseryet it lacks lot of fire power another python libraryxmltodictprovides similar capabilities but uses python' native data structures like dicts to provide more pythonic way to handle xmls the following is quick snippet to parse the same xml unlike elementtreethe parse(function of xmltodict reads file object and converts the contents into nested dictionaries xml_filedata open(file_nameread(ordered_dict xmltodict parse(xml_filedatathe output generated is similar to the one generated using elementtree with the exception that xmltodict uses the symbol to mark elements and attributes automatically the following is the sample output records @attr sample xml records record @name rec_ sub_element detail attribute detail sub_element_with_attr @attr complex #text sub_element_text sub_element_only_attr @attr_val only_attr