I am learning ElementTree in python. Everything seems fine except when I try to parse the xml file with prefix:
test.xml
:
See if this works:
from bs4 import BeautifulSoup
xml_file = "test.xml"
with open(xml_file, "r", encoding="utf8") as f:
contents = f.read()
soup = BeautifulSoup(contents, "xml")
items = soup.find_all("country")
print (items)
The above will produce an array which you can then manipulate to achieve your aim (e.g. remove html tags etc.):
[<country name="Liechtenstein" rank="1" year="2008"> </country>, <country name="Singapore" rank="4" year="2011"> </country>, <country name="Panama" rank="5" year="2011"> </country>]
Add the abc namespace to your xml file.
<?xml version="1.0"?>
<abc:data xmlns:abc="your namespace">