python统计xml节点
来源:互联网 发布:在centos上安装ms8.0 编辑:程序博客网 时间:2024/05/12 15:15
才学python自己编了一个小程序练手
用python对xml的12个节点的个数进行统计。
from xml.dom import minidomimport typesdoc = minidom.parse(r"F:\test\dwr.xml")root = doc.documentElement#listeners = root.getElementsByTagName("listener")child=root.childNodes#print childcount1=0count2=0count3=0count4=0count5=0count6=0count7=0count8=0count9=0count10=0count11=0count12=0for node in child:if node.nodeType==node.ELEMENT_NODE: #print 'ELEMENT_NODE'+' '+node.nodeNamecount1+=1elif node.nodeType==node.ATTRIBUTE_NODE: count2+=1elif node.nodeType==node.TEXT_NODE: count3+=1elif node.nodeType==node.CDATA_SECTION_NODE: count4+=1elif node.nodeType==node.ENTITY_REFRENCE_NODE: count5+=1elif node.nodeType==node.ENTITY_NODE: count6+=1elif node.nodeType==node.PROCESSING_INSTRUCTION_NODE: count7+=1elif node.nodeType==node.COMMENT_NODE: count8+=1elif node.nodeType==node.DOCUMENT_NODE: count9+=1elif node.nodeType==node.DOCUMENT_TYPE_NODE: count10+=1elif node.nodeType==node.DOCUMENT_FRAGENT_NODE: count11+=1elif node.nodeType==node.NOTATION_NODE: count12+=1print '1.ELEMENT_NODE:'+str(count1)print '2.ATTRIBUTE_NODE:'+str(count2)print '3.TEXT_NODE:'+str(count3)print '4.CDATA_SECTION_NODE:'+str(count4)print '5.ENTITY_REFRENCE_NODE:'+str(count5)print '6.ENTITY_NODE:'+str(count6)print '7.PROCESSING_INSTRUCTION_NODE:'+str(count7)print '8.COMMENT_NODE:'+str(count8)print '9.DOCUMENT_NODE:'+str(count9)print '10.DOCUMENT_TYPE_NODE:'+str(count10)print '11.DOCUMENT_FRAGENT_NODE:'+str(count11)print '12.NOTATION_NODE:'+str(count12)
0 0
- python统计xml节点
- [Python]--写xml节点
- python增加xml文件节点
- 【python】写xml节点相关知识
- [python]使用xml.etree.ElementTree遍历xml所有节点
- xml节点
- xml 节点
- XML节点
- python 通过xml获取测试节点和属性
- openstack节点资源统计
- 二叉树统计节点
- 92. 统计节点个数
- 统计叶节点
- inode节点简单统计
- Python xml属性/节点/文本的增删改[xml.etree.ElementTree]
- Python xml属性/节点/文本的增删改[xml.etree.ElementTree]
- Python xml属性/节点/文本的增删改[xml.etree.ElementTree]
- Python xml属性/节点/文本的增删改[xml.etree.ElementTree]
- mysql自查大全
- 状态码详解
- Android中内容观察者的使用---- ContentObserver类详解
- hdu1226 超级密码
- 敏捷开发
- python统计xml节点
- 编程珠玑答案-Chapter3
- hdu 1520 Anniversary party
- 如何保持核心竞争力
- 程序员健康小提示--设置健康的myeclipse工作区背景色
- Android数据库 之 SQLite数据库
- Cannot return from outside a function or method
- ajaxfileupload 文件上传
- mysql5.6配置同步复制的新方法以及常见问题的解决方法