Python etree parsing xml, pythonetreexml
#-*-Coding: UTF-8-*-# conding: UTF-8 _ author _ = 'hdf''' simple and efficient ElementTree lightweight Python APIs, it is provided by a C implementation. Compared with DOM, ET is much faster (see note 3) and many pleasant APIs are available. Compared with SAX, ET also has ET. iterparse, which provides the "in the air" processing method, and does not need to load the entire document to the memory. The average performance of ET is similar to that of SAX ''' import pprintfrom xml. etree. elementTree import parsemapping ={}# retrieve resolution tree = parse ("bools. xml ") # Find all book nodes for B in tree. findall ('book'): # obtain the attribute isbn = B. attrib ['isbn '] # Find the definition of all subnodes under this node as title. for T in B. findall ('title'): # obtain the data text mapping [isbn] = T. textpprint. pprint (mapping)