本文實(shí)例講述了python基于xml parse實(shí)現(xiàn)解析cdatasection數(shù)據(jù)的方法,分享給大家供大家參考。
具體實(shí)現(xiàn)方法如下:
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())
希望本文所述對(duì)大家的Python程序設(shè)計(jì)有所幫助。
更多文章、技術(shù)交流、商務(wù)合作、聯(lián)系博主
微信掃碼或搜索:z360901061

微信掃一掃加我為好友
QQ號(hào)聯(lián)系: 360901061
您的支持是博主寫作最大的動(dòng)力,如果您喜歡我的文章,感覺我的文章對(duì)您有幫助,請(qǐng)用微信掃描下面二維碼支持博主2元、5元、10元、20元等您想捐的金額吧,狠狠點(diǎn)擊下面給點(diǎn)支持吧,站長(zhǎng)非常感激您!手機(jī)微信長(zhǎng)按不能支付解決辦法:請(qǐng)將微信支付二維碼保存到相冊(cè),切換到微信,然后點(diǎn)擊微信右上角掃一掃功能,選擇支付二維碼完成支付。
【本文對(duì)您有幫助就好】元
