私のファイルには次のデータが含まれています。
オリジナル:
<?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>
期待される:
<?xml version="1.0" encoding="UTF-8"?><urlset> <url> <changefreq>daily</changefreq> <loc>http://www.example.com</loc></url></urlset>
etree を使用してファイルを解析し、ルート要素 '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)
初めて root.attrib を印刷したときに {xmlns:" http://www.sitemaps.org/schemas/sitemap/0.9 "}を取得するはずだと思っていましたが、空の辞書を取得しました。誰か助けてくれませんか?
感謝します!