擅长:python、mysql、java
<p>当Save xml add default_namespace参数很容易避免ns0时,在我的代码中</p>
<p>键代码:xmltree.write(xmlfile,“utf-8”,默认的_namespace=xmlnamespace)</p>
<pre><code>if os.path.isfile(xmlfiile):
xmltree = ET.parse(xmlfiile)
root = xmltree.getroot()
xmlnamespace = root.tag.split('{')[1].split('}')[0] //get namespace
initwin=xmltree.find("./{"+ xmlnamespace +"}test")
initwin.find("./{"+ xmlnamespace +"}content").text = "aaa"
xmltree.write(xmlfiile,"utf-8",default_namespace=xmlnamespace)
</code></pre>