当前位置: 移动技术网 > IT编程>脚本编程>Python > python基于xml parse实现解析cdatasection数据

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

2019年03月26日  | 移动技术网IT编程  | 我要评论

德州学院主页,115网址,4399悠悠谷

本文实例讲述了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程序设计有所帮助。

如对本文有疑问,请在下面进行留言讨论,广大热心网友会与你互动!! 点击进行留言回复

相关文章:

验证码:
移动技术网