python基于xml parse實(shí)現(xiàn)解析cdatasection數(shù)據(jù)
本文實(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ì)有所幫助。
- Python實(shí)現(xiàn)提取XML內(nèi)容并保存到Excel中的方法
- Python實(shí)現(xiàn)的讀取/更改/寫入xml文件操作示例
- Python實(shí)現(xiàn)將Excel轉(zhuǎn)換成xml的方法示例
- 利用python實(shí)現(xiàn)xml與數(shù)據(jù)庫讀取轉(zhuǎn)換的方法
- Python實(shí)現(xiàn)對(duì)象轉(zhuǎn)換為xml的方法示例
- 在windows系統(tǒng)中實(shí)現(xiàn)python3安裝lxml
- Python實(shí)現(xiàn)將xml導(dǎo)入至excel
- python實(shí)現(xiàn)XML解析的方法解析
相關(guān)文章
完美解決Python matplotlib繪圖時(shí)漢字顯示不正常的問題
今天小編就為大家分享一篇完美解決Python matplotlib繪圖時(shí)漢字顯示不正常的問題,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。一起跟隨小編過來看看吧2019-01-01Python技法之簡(jiǎn)單遞歸下降Parser的實(shí)現(xiàn)方法
遞歸下降解析器可以用來實(shí)現(xiàn)非常復(fù)雜的解析,下面這篇文章主要給大家介紹了關(guān)于Python技法之簡(jiǎn)單遞歸下降Parser的實(shí)現(xiàn)方法,文中通過示例代碼介紹的非常詳細(xì),需要的朋友可以參考下2022-05-05通過Python收集匯聚MySQL 表信息的實(shí)例詳解
這篇文章主要介紹了通過Python收集匯聚MySQL 表信息的實(shí)例代碼,核心代碼是創(chuàng)建保存數(shù)據(jù)的腳本,收集的功能腳本,代碼簡(jiǎn)單明了,需要的朋友可以參考下2021-10-10Linux下將Python的Django項(xiàng)目部署到Apache服務(wù)器
這篇文章主要介紹了Python的Django項(xiàng)目部署到Apache服務(wù)器上的要點(diǎn)總結(jié),文中針對(duì)的是wsgi連接方式,需要的朋友可以參考下2015-12-12python中日志logging模塊的性能及多進(jìn)程詳解
使用Python來寫后臺(tái)任務(wù)時(shí),時(shí)常需要使用輸出日志來記錄程序運(yùn)行的狀態(tài),并在發(fā)生錯(cuò)誤時(shí)將錯(cuò)誤的詳細(xì)信息保存下來,以別調(diào)試和分析。Python的logging模塊就是這種情況下的好幫手。本文就介紹了python中日志logging模塊性能及多進(jìn)程的相關(guān)資料,需要的朋友可以參考下。2017-07-07