All I'm trying to do is read a local .xml file (encode it UTF-8 so it has the proper header, and re-save the file). However, when I run the following, it adds the dreaded "ns0:" declaration within each XML element:
import xml.etree.ElementTree as ET
import sys, os
# note that this is the *module*'s `register_namespace()` function
# WTF THIS SHOULD WORK....
ET.register_namespace("", "http://www.w3.org/2000/svg")
tree = ET.ElementTree() # instantiate an object of *class* `ElementTree`
tree.parse('//cbweb1/inetpub/x/sitemap/sitemap_index.xml')
tree.write('//cbweb1/inetpub/x/sitemap/test.xml', encoding = 'utf-8', xml_declaration=True)
What am I doing wrong??
FYI, this is Python 2.7.x (have tried with 3.4)
EDIT:
Input:
<sitemapindex xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">
<sitemap>
<loc>http://www.example.com/something.xml</loc>
<lastmod>2014-05-01</lastmod>
</sitemap>
</sitemapindex>
Output:
<?xml version="1.0" encoding="utf-8"?>
<ns0:sitemapindex xmlns:ns0="http://www.sitemaps.org/schemas/sitemap/0.9">
<ns0:sitemap>
<ns0:loc>http://www.example.com/something.xml</ns0:loc>
<ns0:lastmod>2014-05-01</ns0:lastmod>
</ns0:sitemap>
</ns0:sitemapindex>