python xml.etree.ElementTree解析xml文件获取节点
<?xml version = "1.0" encoding = "utf-8"?>
<root>
<body name="lyc">
<age>110</age>
</body>
<body name = "l" age = "10">
</body>
</root> ###################### #coding=UTF8 from xml.etree import ElementTree #xmlText = open("xml.txt").read()
#root = ElementTree.fromstring(xmlText) root = ElementTree.parse("xml.txt")
bodys = root.getiterator("body") #getiterator方法获取
print "getiterator"
print bodys
print dir(bodys[0])
print "attrib:",bodys[0].attrib
print "tag:",bodys[0].tag
print "text",bodys[0].text
#getchildren方法获取
print "getchildren"
children = bodys[0].getchildren()
print children
print "attrib:",children[0].attrib
print "tag:",children[0].tag
print "text:",children[0].text
#find
print "find"
children = root.find("body")
print children
print "attrib:",children.attrib
print "tag:",children.tag
print "text:",children.text
#findall
print "findall"
children = root.findall("body")
print children
print "attrib:",children[0].attrib
print "tag:",children[0].tag
print "text:",children[0].text
aa = xml.dom.minidom.parseString(response_res).documentElement.getElementsByTagName('string')[0].childNodes[0].data
doc = etree.XML(aa)
doc.xpath("//BoardData")[0].getchildren()[0].text
python xml.etree.ElementTree解析xml文件获取节点的更多相关文章
- python3.x中xml.etree.ElementTree解析xml举例
1.新建xml import xml.etree.ElementTree as ETa=ET.Element('elem')c=ET.SubElement(a,'child1')c.text=&quo ...
- Python中xml.etree.ElementTree读写xml文件实例
import osimport xml.etree.ElementTree as ET'''Python 标准库中,提供了6种可以用于处理XML的包,本文举实例说明第6种1.xml.dom2.xml. ...
- Python中使用ElementTree解析xml
在Python中,ElementTree是我们常用的一个解析XML的模块 1.导入ElementTree模块 from xml.etree import ElementTree as ET 2.初始化 ...
- python xml.etree ElementTree解析 编辑 xml
python有很多种xml解析方式,不过感觉etree的ElementTree 用起来最方便. #coding=utf-8 from xml.etree import ElementTree impo ...
- python解析xml文件之xml.etree.cElementTree和xml.etree.ElementTree区别和基本使用
1.解析速度:ElementTree在 Python 标准库中有两种实现.一种是纯 Python 实现例如 xml.etree.ElementTree ,另外一种是速度快一点的 xml.etree.c ...
- python XML文件解析:用ElementTree解析XML
Python标准库中,提供了ET的两种实现.一个是纯Python实现的xml.etree.ElementTree,另一个是速度更快的C语言实现xml.etree.cElementTree.请记住始终使 ...
- python 解析xml遇到xml.etree.ElementTree.ParseError: not well-formed (invalid token): line 4, column 34
在调试数字驱动用xml文件的方式时,包含读取xml文件的步骤,运行程序报错: d:\test\0629>python XmlUtil.pyTraceback (most recent call ...
- [python]使用ElementTree解析XML【译】
19.7 The ElementTree XML API 源码:Lib/xml/etree/ElementTree.py Element类型是一个灵活的容器对象,设计出来是用于存储有层次的数据结构到内 ...
- ZH奶酪:Python使用ElementTree解析XML【译】
19.7. xml.etree.ElementTree — The ElementTree XML API 源代码: Lib/xml/etree/ElementTree.py Element类型是一种 ...
随机推荐
- Shiro过滤器的维护与匹配执行
servlet的初始化会触发核心过滤器的创建: public Object getObject() throws Exception { if (instance == null) { instanc ...
- Oracle常用常考集合
登陆远程服务器 sqlplus scott/tiger@192.168.2.1[:port]/sid [as sysdba] 简单查询 select table_name from user_tab ...
- Linux基础系列-Day1
Linux发展简史 Unix:1969年由美国电话电报公司(AT&T)贝尔实验室的两个工程师所创造的操作系统,它允许计算机同时处理多用户和程序. BSD:重要的Unix分支,1977年由加州大 ...
- PMP的六大管理学定律
★墨菲定律PMP考试六大管理学定律之1-PMP专业辅导 1.什么是墨菲定律?最简单的表达形式是“有可能出错的事情,就会出错(Anything that can go wrong will go wro ...
- 安卓 内容提供者 sql 区别
韩梦飞沙 韩亚飞 313134555@qq.com yue31313 han_meng_fei_sha 内容提供者 用户只需关心 操作数据的url 就可以了. 实现 了 应用间 数据共享.可以操作数据 ...
- [BZOJ2595]游览计划
斯坦纳树居然不是数据结构... 斯坦纳树应该是类似最小生成树的问题,只不过它允许增加额外的点 比如这道题就是找关于景点的最小生成树,但还要付出最小的代价,加一些额外的格子把景点都连起来 套路是设$f_ ...
- Java高级架构师(一)第35节:Nginx的Location区段
没有修饰符 表示:必须以指定模式开始. 表示/abc下的所有内容都可以被访问. = 表示与指定的模式精确匹配,可以带参数. 实例中要求区分大小写,并以c结尾. 实例中指定的正则表达式不区分大小写. 注 ...
- js中propertyIsEnumerable()方法使用介绍
javascript的propertyIsEnumerable()方法使用介绍 概述 propertyIsEnumerable()用来检测属性是否属于某个对象的,如果检测到了,返回true,否则fal ...
- uboot中的快捷菜单的制作说明
转:http://blog.chinaunix.net/uid-22030783-id-366971.html 在uboot中加入快捷操作菜单的方法非常简单,在论坛发布的uboot201003V1.1 ...
- Bower管理依赖库初体验
比如一开始我用了jquery-1.10.2.min.js,后来要用bootstrap,但bootstrap依赖的确实2.0.3版本的jquery,那又要下载一个去替换原来的,这样的事情发生多了就会觉得 ...