XML结构如下:
<LR basepoints="111">
<variable index="1" name="app_sdfad">
<value index="0" start="missing" end="missing" points="5"/>
<value index="1" start="-Inf" end="1.0" points="35"/>
<value index="2" start="1.0" end="2.0" points="24"/>
<value index="3" start="2.0" end="4.0" points="7"/>
<value index="4" start="4.0" end="5.0" points="-4"/>
<value index="5" start="5.0" end="Inf" points="-43"/>
</variable>
</LR>
import xml.etree.ElementTree as ET
def parseXML(self):
tree = ET.parse(self.xml)
root = tree.getroot()
dict = {}
if len(root) > 0:
for child in root:
list = []
for grandson in child:
del grandson.attrib['index']
list.append(grandson.attrib)
dict[child.attrib['name']] = list
return dict, root.attrib['basepoints']
parseXML('test.xml')