Python 删除“;xmlns:py…“;使用lxml.objectify
我刚刚发现了Python 删除“;xmlns:py…“;使用lxml.objectify,python,xml,xml-parsing,lxml,Python,Xml,Xml Parsing,Lxml,我刚刚发现了lxml.objectify,它看起来很好,而且很容易读/写简单的XML文件 首先,使用lxml.objectify是一个好主意吗?例如,它是否成熟,是否仍在开发中,是否可能在未来提供 其次,如何防止objectify添加类似xmlns:py=”的标记http://codespeak.net/lxml/objectify/pytype“py:pytype=“str”在下面的输出中?” 输入:config.xml <?xml version="1.0" encoding="ut
lxml.objectify
,它看起来很好,而且很容易读/写简单的XML文件
首先,使用lxml.objectify
是一个好主意吗?例如,它是否成熟,是否仍在开发中,是否可能在未来提供
其次,如何防止objectify
添加类似xmlns:py=”的标记http://codespeak.net/lxml/objectify/pytype“py:pytype=“str”
在下面的输出中?”
输入:config.xml
<?xml version="1.0" encoding="utf-8"?>
<Test>
<MyElement1>sdfsdfdsfd</MyElement1>
</Test>
输出
<Test>
<MyElement1>sdfsdfdsfd</MyElement1>
<Information xmlns:py="http://codespeak.net/lxml/objectify/pytype" py:pytype="str">maybe</Information>
</Test>
sdfsdfdsfd
大概
正如这里指出的:,这足以防止出现此xmlns
标记:
objectify.deannotate(root, xsi_nil=True)
etree.cleanup_namespaces(root)
从lxml 2.3.2版开始,您可以将
cleanup\u namespaces=True
传递到objectify.deannotate()
(无需调用etree.cleanup\u namespaces()
)
objectify.deannotate(root, xsi_nil=True)
etree.cleanup_namespaces(root)