python解析XML之ElementTree
#coding=utf-8
from xml.etree import ElementTree as ET
tree=ET.parse('test.xml')
root = tree.getroot()
#p=per.findall('caption') #for oneper in p:
# for child in oneper.getchildren():
# print child.tag,':',child.text
#for node in root.findall('caption'):
# print node.tag pe=root.findall('./item')
first = 0
second = 0
third = 0
for child in pe:
# for child in oneitem.getchildren():
print "the first layer-------------" print child.tag,'tag:',child.text,'attr:' ,child.attrib
second_child=child.findall('./item')
first+=1
for thirdchild in second_child:
print "the second layer=========="
gchild=thirdchild.findall('./item')
print thirdchild.tag,'tag:',thirdchild.text,'attr:' ,thirdchild.attrib
second+=1
# print gchild.tag,'-88-:',gchild.text
# print type(gchild)
for i in gchild:
print "the third layer 3333333333"
print "i in child %s"%i
print i.tag,'-5656-:',i.text,'attr:' ,i.attrib
third+=1 print "first =%d\n"%first
print "second=%d\n"%second
print "third =%d\n"%third
<?xml version="1.0" encoding="utf-8"?> <catalog>
<service>4</service>
<item id="1">
<item id="11">
<caption>c1</caption>
<caption>c2</caption>
<caption>c3</caption>
</item>
</item> <item id="9">
<item id="99">
<item id="999">
</item>
</item>
</item>
<item id="8">
<item id="88">
<item id="888">
</item>
</item>
</item>
<item id="2">
<caption> </caption>
</item>
<item id="3">
<caption>
<item>itemc4</item>
<book>Zope2</book>
</caption>
</item> <item id="4">
<caption>c5</caption>
</item> <item id="5">
<caption>c6</caption>
<caption>c7</caption>
</item> <item>item6</item>
<item>item7</item> </catalog>
python解析XML之ElementTree的更多相关文章
- python 解析xml
		在工作中很多时候都要用到xml,使用这个时候难免会设计到解析他,然后就研究了一下python解析xml问题,看了很多东西,python有很多解析xml的包,但是也折腾我好一段时间,最后选择了这个方法. ... 
- Python 解析 XML 文件生成 HTML
		XML文件result.xml,内容如下: <ccm> <metric> <complexity>1</complexity> <unit> ... 
- 横向对比分析Python解析XML的四种方式
		横向对比分析Python解析XML的四种方式 在最初学习PYTHON的时候,只知道有DOM和SAX两种解析方法,但是其效率都不够理想,由于需要处理的文件数量太大,这两种方式耗时太高无法接受. 在网络搜 ... 
- python 解析XML python模块xml.dom解析xml实例代码
		分享下python中使用模块xml.dom解析xml文件的实例代码,学习下python解析xml文件的方法. 原文转自:http://www.jbxue.com/article/16587.html ... 
- python解析xml模块封装代码
		在python中解析xml文件的模块用法,以及对模块封装的方法.原文转自:http://www.jbxue.com/article/16586.html 有如下的xml文件:<?xml vers ... 
- python解析xml之lxml
		虽然python解析xml的库很多,但是,由于lxml在底层是用C语言实现的,所以lxml在速度上有明显优势.除了速度上的优势,lxml在使用方面,易用性也非常好.这里将以下面的xml数据为例,介绍l ... 
- python解析xml
		python解析xml import xml.dom.minidom as minidom dom = minidom.parse("aa.xml") root = dom.get ... 
- Python 解析XML实例(xml.sax)
		已知movies.xml <collection shelf="New Arrivals"> <movie title="Enemy Behind&qu ... 
- python解析xml文件时使用ElementTree和cElementTree的不同点;iter
		在python中,解析xml文件时,会选用ElementTree或者cElementTree,那么两者有什么不同呢? 1.cElementTree速度上要比ElementTree快,比较cElemen ... 
随机推荐
- Nimbus<二>storm启动nimbus源码分析-nimbus.clj
			nimbus是storm集群的"控制器",是storm集群的重要组成部分.我们可以通用执行bin/storm nimbus >/dev/null 2>&1 &a ... 
- wuzhi 五指 基本知识
			参数:m 模块 在于 /coreframe/app/模块文件夹 |默认 content f php文件 控制器 在于/coreframe/app/模块 /文件.php | 默认 index v ... 
- 37.看下图实现如下接口和类,并完成Adventure中的主方法。
			//接口Swim package jieKou; public interface ICanswim { void Swim(); } //接口Fly package jieKou; public i ... 
- iOS 加载本地的html文件
			方法1: self.webView = [[UIWebView alloc]initWithFrame:self.view.bounds]; NSString *path = [[NSBundle ... 
- 域名、网站名、url的定义
			网址:http://jingyan.baidu.com/article/2c8c281df0afd00008252aa7.html 
- Tcp  Socket非阻塞recv
			最近看了许多关于网络编程的资料,自己小记一下,以方便以后查找. 什么是阻塞socket,什么是非阻塞socket.对于这个问题,我们要先弄清什么是阻塞/非阻塞.阻塞与非阻塞是对一个文件描述符指定的文件 ... 
- 测试sql性能方法
			SET STATISTICS io ON SET STATISTICS time ON go ---你要测试的sql语句 selec ... 
- Python使用ctypes访问C代码
			工具:CodeBlocks 新建一个分享库工程( Shared library ),随便编写一个C代码的函数 // test.c #include <stdio.h> int fib(in ... 
- MapReduce初级案例
			1.数据去重 "数据去重"主要是为了掌握和利用并行化思想来对数据进行有意义的筛选.统计大数据集上的数据种类个数.从网站日志中计算访问地等这些看似庞杂的任务都会涉及数据去重.下面就 ... 
- phpstudy vhost 配置
			server { listen 80 ; server_name user.fudaobank.com; index index.html index.htm index.php; root /ali ... 
