自信,努力,坚持
python xml解析
上一篇 /
下一篇 2011-07-26 14:12:19
/ 个人分类:python
1、使用xml.etree.ElementTree解析
2、加载XML有两种方式,一是加载指定字符串,二是加载指定文件
3、获取element的方法
a) 通过getiterator
b) 过 getchildren
c) find方法
d) findall方法
举例:
1、加载指定字符串
output="<commands><command><type>loginprofile</type><result>1</result><message></message></command></commands>"
element=ET.fromstring(output.encode("utf-8"))
for key in expect:
lst_node = element.getiterator(key) //这里用find,findall,getchildren都不可以,原因不明
for node in lst_node:
print node.tag, node.text
参考文档:http://archive.cnblogs.com/a/1886743/
收藏
举报
TAG: