xml extends markup language, which can be used to mark data and define data types. xml is a source language that allows users to define their own markup language.
ElementTree is python's XML processing module, which provides a lightweight object model. When using the ElementTree module, you need the operation of import xml.etree.ElementTree. ElementTree represents the entire XML node tree, while Element represents a single node in the number of nodes.
XML Example 1: Use XML to read the local first.xml file and parse the data
The following is the content of the first.xml file
View Code![]()
1 <data> 2 <country name="Liechtenstein"> 3 <rank updated="yes">2</rank> 4 <year>2023</year> 5 <gdppc>14110</gdppc> 6 <neighbor direction="E" name="Austria"/> 7 <neighbor direction="W" name="switzeriand"/> 8 </country> 9 <country name="Singapore"> 10 <rank updated="yes">5</rank> 11 <year>2026</year> 12 <gdppc>59900</gdppc> 13 <neighbor direction="N" name="Malaysia"/> 14 </country> 15 <country name="Faname"> 16 <rank updated="yes">69</rank> 17 <year>2019</year> 18 <gdppc>13360</gdppc> 19 <neighbor direction="W" name="Costa Rica"/> 20 <neighbor direction="E" name="Colombia"/> 21 </country> 22 </data>