<?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文件获取节点的更多相关文章

  1. 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 ...

  2. Python中xml.etree.ElementTree读写xml文件实例

    import osimport xml.etree.ElementTree as ET'''Python 标准库中,提供了6种可以用于处理XML的包,本文举实例说明第6种1.xml.dom2.xml. ...

  3. Python中使用ElementTree解析xml

    在Python中,ElementTree是我们常用的一个解析XML的模块 1.导入ElementTree模块 from xml.etree import ElementTree as ET 2.初始化 ...

  4. python xml.etree ElementTree解析 编辑 xml

    python有很多种xml解析方式,不过感觉etree的ElementTree 用起来最方便. #coding=utf-8 from xml.etree import ElementTree impo ...

  5. python解析xml文件之xml.etree.cElementTree和xml.etree.ElementTree区别和基本使用

    1.解析速度:ElementTree在 Python 标准库中有两种实现.一种是纯 Python 实现例如 xml.etree.ElementTree ,另外一种是速度快一点的 xml.etree.c ...

  6. python XML文件解析:用ElementTree解析XML

    Python标准库中,提供了ET的两种实现.一个是纯Python实现的xml.etree.ElementTree,另一个是速度更快的C语言实现xml.etree.cElementTree.请记住始终使 ...

  7. 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 ...

  8. [python]使用ElementTree解析XML【译】

    19.7 The ElementTree XML API 源码:Lib/xml/etree/ElementTree.py Element类型是一个灵活的容器对象,设计出来是用于存储有层次的数据结构到内 ...

  9. ZH奶酪:Python使用ElementTree解析XML【译】

    19.7. xml.etree.ElementTree — The ElementTree XML API 源代码: Lib/xml/etree/ElementTree.py Element类型是一种 ...

随机推荐

  1. 【BZOJ 2809】2809: [Apio2012]dispatching (左偏树)

    2809: [Apio2012]dispatching Description 在一个忍者的帮派里,一些忍者们被选中派遣给顾客,然后依据自己的工作获取报偿.在这个帮派里,有一名忍者被称之为 Maste ...

  2. sg函数总结

    http://blog.csdn.net/luomingjun12315/article/details/45555495 这一段时间写的题和我接下来要展示的一些概念都来自这里↑. 必胜点和必败点的概 ...

  3. [2018湖南省队集训] 6.24 T1 marshland

    题面在这里! 一开始感觉像一个类似二分图的最小割,于是成功跑偏2333333 很容易发现一个关键性质,'L'的两个角落在的偶数格 的行(或者列)的奇偶性一定不同.... 于是我们再把偶数格按照行(或者 ...

  4. js知识-进阶

    1 DOM 1.1 查找标签 (1)直接查找 document.getElementById(“idname”)          // dom对象 document.getElementsByTag ...

  5. trim()函数 mysql中的强大字符串过滤函数

    mysql中功能强大的trim()函数. 去除两边空格: mysql> select trim(' hello world '); +-----------------------+ | tri ...

  6. #iOS问题记录# UITextview富文本链接,禁止长按事件

    UITextView的富文本组装,添加图片点击事件,启动 - (BOOL)textView:(UITextView *)textView shouldInteractWithURL:(NSURL *) ...

  7. 使用hosts.allow和hosts.deny实现简单的防火墙

    说明:我建议学习防火墙只单一学习一种就够了,这种方式虽然简单和快速,但也有些不太灵活,所以如果要深入防火墙建议转iptables  一.背景简介 在Linux上多用iptables来限制ssh和tel ...

  8. jquery-qrcode 生成和读取二维码

    首先要导入jar包(生成二维码的jar和读取二维码的jar) 生成二维码: package com.imooc.qrcode; import java.awt.Color; import java.a ...

  9. 支持向量机SVM 简要推导过程

    SVM 是一块很大的内容,网上有写得非常精彩的博客.这篇博客目的不是详细阐述每一个理论和细节,而在于在不丢失重要推导步骤的条件下从宏观上把握 SVM 的思路. 1. 问题由来 SVM (支持向量机) ...

  10. Ceph源码解析:读写流程

    转载注明出处,整理也是需要功夫的,http://www.cnblogs.com/chenxianpao/p/5572859.html 一.OSD模块简介 1.1 消息封装:在OSD上发送和接收信息. ...