简体   繁体   中英

python xml library with similar functionality to json library

Python has a json library where you can do json.loads(s) to load json into a python data structure consisting of lists and maps. Is there something equivalent for xml? All the xml libraries I've seen map to a DOM where you have to know special API functions, which is IMO less easy to work with.

No, on the simple note that JSON objects directly translate to Python objects. How do you turn XML into Python - the answer is the DOM.

There are, however, simpler ways to work with XML. The best, in my opinion, for ease of use, is xml.etree.ElementTree , which allows you to iterate through the elements of the XML and create a tree, which is pretty easy to work with comparable with other ways of getting at XML data.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM