My file contains the following data:
Original:
<?xml version="1.0" encoding="UTF-8"?><urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9"> <url> <changefreq>daily</changefreq> <loc>http://www.example.com</loc></url></urlset>
Expected:
<?xml version="1.0" encoding="UTF-8"?><urlset> <url> <changefreq>daily</changefreq> <loc>http://www.example.com</loc></url></urlset>
I use etree to parse the file and I want to remove the attribute from the root element 'urlset'
import xml.etree.ElementTree as ET
tree = ET.parse("/Users/hsyang/Downloads/VI-0-11-14-2016_20.xml")
root = tree.getroot()
print root.attrib
>> {}
root.attrib.pop("xmlns", None)
print root.attrib
>> {}
ET.tostring(root)
I thought I was supposed to get {xmlns:"http://www.sitemaps.org/schemas/sitemap/0.9"} when i print root.attrib the first time but I got an empty dictionary. Can someone help?
Appreciate it!