python基于xml parse实现解析cdatasection数据

yipeiwu_com6年前Python基础

本文实例讲述了python基于xml parse实现解析cdatasection数据的方法,分享给大家供大家参考。

具体实现方法如下:

from xml.dom.minidom import * 
 
implementation = DOMImplementation() 
 
print "Core:%s" % implementation.hasFeature('core', '2.0') 
print "Events:%s" % implementation.hasFeature('Events', '2.0') 
print "Traversal:%s" % implementation.hasFeature('Traversal', '2.0') 
print "Views:%s" % implementation.hasFeature('Views', '2.0') 
print "features:%s" % implementation._features 
     
dom = parse("result.xml")  
domRoot = dom.documentElement 
print domRoot 
print domRoot.nodeType 
print "ELEMENT_NODE:%s " % dom.ELEMENT_NODE 
print "ATTRIBUTE_NODE:%s " % dom.ATTRIBUTE_NODE 
 
children = domRoot.childNodes 
for child in children: 
  print "child_get_tagName:%s" % child._get_tagName() 
  print "child_get_localName:%s" % child._get_localName() 
  print "child.hasChildNodes:%s" % child.hasChildNodes() 
  if child._get_tagName() == "files_rg": 
    files = child._get_childNodes() 
    for file in files: 
      if file.nodeType == dom.ELEMENT_NODE: 
        for node in file._get_childNodes(): 
          print "node.childNodes:%s ",node._get_childNodes() 
          for cdataSection in node._get_childNodes(): 
            if cdataSection.nodeType == dom.CDATA_SECTION_NODE: 
              print "cdataSection._get_data:%s %s " % (cdataSection._get_localName(),cdataSection._get_data()) 

希望本文所述对大家的Python程序设计有所帮助。

相关文章

Python堆排序原理与实现方法详解

Python堆排序原理与实现方法详解

本文实例讲述了Python堆排序原理与实现方法。分享给大家供大家参考,具体如下: 在这里要事先说明一下我也是新手,很多东西我了解不是很深入,写算法完全是锻炼自己逻辑能力同时顺带帮助读研的...

python存储16bit和32bit图像的实例

笔记:python中存储16bit和32bit图像的方法。 说明:主要是利用scipy库和pillow库,比较其中的不同。 ''' 测试16bit和32bit图像的python存储方...

python 获取sqlite3数据库的表名和表字段名的实例

Python中对sqlite3数据库进行操作时,经常需要用到字段名,然而对于sqlite使用select语句并不能象MySql等数据库一样返回带字段名的字典数据集。特别是对于一个不熟悉的...

在Django中管理Users和Permissions以及Groups的方法

管理认证系统最简单的方法是通过管理界面。然而,当你需要绝对的控制权的时候,有一些低层 API 需要深入专研,我们将在下面的章节中讨论它们。 创建用户 使用 create_user 辅助函...

Python 面向对象 成员的访问约束

在Python中是通过一套命名体系来识别成约的访问范围的 class MyObjec(object): username = "developerworks" # public _ema...