我有下一个XML:
data3.xml:个
<?xml version="1.0" encoding="UTF-8"?>
<feed
xmlns="http://www.w3.org/2005/Atom">
<entry>
<content>
<ns2:executionresult
xmlns:ns2="http://jazz.net/xmlns/alm/qm/v0.1/"
xmlns:ns4="http://purl.org/dc/elements/1.1/">
<ns4:title>xxx</ns4:title>
</ns2:executionresult>
</content>
</entry>
</feed>
我有下一个代码:
test3.py:
import xml.etree.ElementTree as ET
tree = ET.parse('data3.xml')
root = tree.getroot()
xml_str = ET.tostring(root).decode()
print(xml_str)
Output:个
$ python3 test3.py
<ns0:feed xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:ns0="http://www.w3.org/2005/Atom" xmlns:ns1="http://jazz.net/xmlns/alm/qm/v0.1/">
<ns0:entry>
<ns0:content>
<ns1:executionresult>
<dc:title>xxx</dc:title>
</ns1:executionresult>
</ns0:content>
</ns0:entry>
</ns0:feed>
我想知道为什么ElementTree
会自动为我更改namespace
?规则是什么?我怎么才能避免它呢?