我有这样一个xml:
<?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将它改成这样:
^{pr2}$我试着用对象化。取消注释来自lxml模块。 但没用。 你能帮我达到目的吗?在
考虑一下XSLT,这是一种专门用来转换XML文件的语言,比如删除名称空间。Python的第三方模块
lxml
,可以运行xslt1.0脚本。因为XSLT脚本是XML文件,所以可以像任何XML一样从文件或字符串进行解析。不需要循环或条件if
逻辑。此外,您还可以在其他语言(PHP、Java、C#等)中使用这个XSLT脚本XSLT(另存为.xsl文件,在Python中引用)
Python
^{pr2}$输出
{a2是一个名称空间的组合,显示了如何修改^的名称空间。在
代码有点粗糙(我特别怀疑使用
_setroot
方法是否符合犹太教规),但它似乎有效:给定示例输入,将在
^{pr2}$done.xml
中生成:相关问题 更多 >
编程相关推荐