36 # C:UsersjeguanDesktopTest_1.txt
37 #
38 # <?xml version="1.0"?>
39 # <data>
40 # <country name="Liechtenstein">
41 # <rank>1</rank>
42 # <year>2008</year>
43 # <gdppc>141100</gdppc>
44 # <neighbor name="Austria" direction="E"/>
45 # <neighbor name="Switzerland" direction="W"/>
46 # </country>
47 # <country name="Singapore">
48 # <rank>4</rank>
49 # <year>2011</year>
50 # <gdppc>59900</gdppc>
51 # <neighbor name="Malaysia" direction="N"/>
52 # </country>
53 # <country name="Panama">
54 # <rank>68</rank>
55 # <year>2011</year>
56 # <gdppc>13600</gdppc>
57 # <neighbor name="Costa Rica" direction="W"/>
58 # <neighbor name="Colombia" direction="E"/>
59 # </country>
60 # </data>
61 #######################################################################
62 def func2():
63 from xml.etree import ElementTree
64 xlsfile = r'C:UsersjeguanDesktopTest_1.txt'
65
66 root = ElementTree.parse(xlsfile).getroot()
67 <span style="color:#FF0000;"><strong><span style="font-size:18px;"> ListNode = root.getiterator('rank')</span></strong></span>
68 print(ListNode)
69 # the output for print(ListNode) [<Element 'rank' at 0x6ffffc51450>, <Element 'rank' at 0x6ffffc51810>, <Element 'rank' at 0x6ffffc51950>]
70 <span style="font-size:18px;color:#FF0000;"><strong>children = root.getchildren()</strong></span>
71 print(children)
72 # the output for print(children) is [<Element 'country' at 0x6ffffc50410>, <Element 'country' at 0x6ffffc507d0>, <Element 'country' at 0x6ffffc50910>]
https://github.com/double12gzh/PythonLearning/blob/master/ElementTree.py