python etree瑙f瀽xml,,鏍囩锛?/p>#
python etree瑙f瀽xml,,鏍囩锛?/p>#
鏍囩锛?/p>
# -*- coding:utf-8 -*-#conding:utf-8__author__ = 鈥?/span>hdfs鈥?/span>鈥樷€樷€?/span>绠€娲?楂樻晥 鏄庝簡ElementTree杞婚噺绾х殑 Python 寮忕殑 API 锛?瀹冪敱涓€涓?C 瀹炵幇鏉ユ彁渚涖€?鐩稿浜?DOM 鏉ヨ锛?ET 蹇簡寰堝(瑙佹敞閲?)鑰屼笖鏈夊緢澶氫护浜烘剦鎮︾殑 API 鍙互浣跨敤銆?鐩稿浜?SAX 鏉ヨ锛孍T 涔熸湁 ET.iterparse 鎻愪緵浜?“鍦ㄧ┖涓?rdquo; 鐨勫鐞嗘柟寮忥紝娌℃湁蹇呰鍔犺浇鏁翠釜鏂囨。鍒板唴瀛樸€?ET 鐨勬€ц兘鐨勫钩鍧囧€煎拰 SAX 宸笉澶?鈥樷€樷€?/span>import pprintfrom xml.etree.ElementTree import parsemapping={}#鑾峰彇瑙f瀽鏍?/span>tree=parse("bools.xml")#鎵惧埌鎵€鏈夌殑book鑺傜偣for B in tree.findall(鈥?/span>book鈥?/span>): #鑾峰彇灞炴€?/span> isbn=B.attrib[鈥?/span>isbn鈥?/span>] #鎵惧埌璇ヨ妭鐐逛笅鐨勬墍鏈夊瓙鑺傜偣涓簍itle鐨勭晫瀹氬晩 for T in B.findall(鈥?/span>title鈥?/span>): #鑾峰彇鏁版嵁鏂囨湰 mapping[isbn]=T.textpprint.pprint(mapping)
python etree瑙f瀽xml
鏍囩锛?/p>
鍘熸枃鍦板潃锛歨ttp://www.cnblogs.com/similarface/p/5135209.html
相关内容
- 暂无相关文章
评论关闭