学会思考
刻意练习
1 import xml.etree.ElementTree as ET
2 tree = ET.parse('E:\\test\\xx.xml')
3 root = tree.getroot()
4 print(root)
5 
6 for city in root.iter('city'):
7     print(city.get('cityName'),city.get('quName'))

假设处理xml文件如下:xx.xml

<china dn = "nay">
<city quName="heikongjiang" pyName="heihei" cityName="ha2ging"/>
<city quName="heikongjiang" pyName="heihei" cityName="ha2ging"/>
<city quName="heikongjiang" pyName="heihei" cityName="ha3ging"/>
<city quName="heikongjiang" pyName="heihei" cityName="ha3ging"/>
<city quName="heikongjiang" pyName="heihei" cityName="ha4ging"/>
<city quName="heikongjiang" pyName="heihei" cityName="ha1ging"/>
<city quName="heikongjiang" pyName="heihei" cityName="ha2ing"/>
</china>

posted on 2018-09-14 23:03  Worty  阅读(969)  评论(0编辑  收藏  举报