我所要做的就是读取一个local.xml文件(将其编码为UTF-8,使其具有正确的头,然后重新保存该文件)。但是,当我运行以下命令时,它会在每个XML元素中添加可怕的“ns0:”声明: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)
我做错什么了??在
仅供参考,这是python2.7.x(已经尝试过3.4)
编辑:
输入:
^{pr2}$
输出:<?xml version="1.0" encoding="utf-8"?>
http://www.example.com/something.xml
2014-05-01