您的位置:首页 > 编程语言 > Python开发

Python parse XML

2015-04-01 00:03 225 查看
解析xml 使用下列 library

import xml.etree.ElementTree as ET

tree = ET.parse( ‘xxx.xml’ )

找到所有特定的 tag

for ind, obj in enumerate( tree.iter(tag=’object’) ):

pass

找特定的 tag 和及其 attribute

#obj 是其中一个子结构

a = obj.find(‘bndbox’).find(‘xmax’).text

上面代码找到如下子结构中的数字

[code]<obj>
    <bndbox>
            <xmax> 352 </xmax>
    </bndbox>
</obj>
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: