我必须使用lxml或者甚至xml.etree.ElementTree模块
<?xml version="1.0"?>
<corners>
<version>1.05</version>
<process>
<name>ss649</name>
<statistics>
<statistic name="Min" forparameter="modname" isextreme="no" style="tbld">
<value>0.00073</value>
<real_value>7.300e-10</real_value>
</statistic>
<statistic name="Max" forparameter="modname" isextreme="no" style="tbld">
<value>0.32420</value>
<real_value>3.242e-07</real_value>
</statistic>
<variant>
<name>Unit</name>
<value>
<value>Size</value>
<statistics>
<statistic name="Min" forparameter="modname1" isextreme="no" style="tbld">
<value>0.02090</value>
<real_value>2.090e-08</real_value>
</statistic>
<statistic name="Max" forparameter="modname2" isextreme="no" style="tbld">
<value>0.02090</value>
<real_value>2.090e-08</real_value>
</statistic>
</variant>
我必须把所有的值都取出来,然后做一个Dict,这个值是哪个,但是我不能访问子树,我该怎么做呢?在
尝试创建一个像这样的dict
^{pr2}$
您可能希望看看这个相当不错的ActiveState片段:
http://code.activestate.com/recipes/410469-xml-as-dictionary/
我是通过下面的SO帖子看到的,这个帖子可能也有用:
How to convert an xml string to a dictionary in Python?
xmltodict也是一个不错的选择:
https://github.com/martinblech/xmltodict
xmltodict绝对是您应该考虑使用的内容:
一行代码,你就可以走了。在
希望对你有用。在
我使用了
xml.etree.ElementTree
模块输出:
^{pr2}$相关问题 更多 >
编程相关推荐