Python etree parsing xml, pythonetreexml

Source: Internet
Author: User

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)

 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.