xml.etree.ElementTree — The ElementTree XML API ... | python xml.etree.elementtree subelement
Thexml.etree.ElementTree[1]moduleimplementsasimpleandefficientAPIforparsingandcreatingXMLdata.TutorialThisisashorttutorialforusingxml.etree.ElementTree[2](ETinshort).Thegoalistodemonstratesomeofthebuildingblocksandbasicconceptsofthemodule.XMLtreeandelementsXMLisaninherentlyhierarchicaldataformat,andthemostnaturalwaytorepresentitiswithatree.EThastwoclassesforthispurpose-ElementTree[3]representsthewholeXMLdocumentasatree,andElement[4]representsasinglenodeinthistree.Interactionswiththewholedocu...
The xml.etree.ElementTree[1] module implements a simple and efficient API for parsing and creating XML data.
TutorialThis is a short tutorial for using xml.etree.ElementTree[2] (ET in short). The goal is to demonstrate some of the building blocks and basic concepts of the module.
XML tree and elementsXML is an inherently hierarchical data format, and the most natural way to represent it is with a tree. ET has two classes for this purpose - ElementTree[3] represents the whole XML document as a tree, and Element[4] represents a single node in this tree. Interactions with the whole document (reading and writing to/from files) are usually done on the ElementTree[5] level. Interactions with a single XML element and its sub-elements are done on the Element[6] level.
Parsing XMLWe’ll be using the following XML document as the sample data for this section:
<?xml version="1.0"?> <data> <country name="Liechtenstein"> <rank>1&l...