number.xml
<?xml version="1.0" encoding="utf-8"?>
<ResponseSent>
<ResponseDate xmlns="http://example.com/schema">
<emailid>123@test.com</emailid>
<number>22</number>
<sent>2017-12-05</sent>
</ResponseDate>
number.py
import xml.etree.ElementTree as ET
tree = ET.parse('number.xml')
root = tree.getroot()
for country in root.findall('ResponseDate'):
rank = country.find('emailid').text
name = country.find('number').text
print(name, rank)
Returning empty results, but when I modify the xml to name= instead of xmlns= then it is working. But, how to make this script work with the xmlns.?
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…