我有這樣一個xml:如何從Python中的XML中刪除ns?
<?xml version="1.0" encoding="UTF-8"?>
<ns0:epp xmlns:ns0="urn:ietf:params:xml:ns:epp-1.0"
xmlns:ns1="http://epp.nic.ir/ns/contact-1.0">
<ns0:command>
<ns0:check>
<ns1:check>
<ns1:id>ex61-irnic</ns1:id>
<ns1:id>ex999-irnic</ns1:id>
<ns1:authInfo>
<ns1:pw>1487441516170712</ns1:pw>
</ns1:authInfo>
</ns1:check>
</ns0:check>
<ns0:clTRID>TEST-12345</ns0:clTRID>
</ns0:command>
</ns0:epp>
我想用Python 3中來改變它是這樣的:
<?xml version="1.0" encoding="UTF-8"?>
<epp xmlns="urn:ietf:params:xml:ns:epp-1.0">
<command>
<check>
<check>
<id>ex61-irnic</id>
<id>ex999-irnic</id>
<authInfo>
<pw>1487441516170712</pw>
</authInfo>
</check>
</check>
<clTRID>TEST-12345</clTRID>
</command>
</epp>
我試圖從LXML模塊objectify.deannotate刪除納秒。 但它沒有奏效。 你能幫我達成我的目標嗎?
只要做一個簡單的查找和替換/刪除字符串的'ns1:'或'ns0:' – AK47
...當然如果字符串「ns1:」被包含在某個地方而不是命名空間符。 – larsks