【发布时间】:2018-10-18 20:30:19
【问题描述】:
在我正在查看的文件上传文档中,它需要在 xml 文件的开头使用这个特定的标签:
<oclcPersonas xmlns="http://worldcat.org/xmlschemas/IDMPersonas-2.2"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://worldcat.org/xmlschemas/IDMPersonas-2.2 IDMPersonas-2.2.xsd">
我正在尝试使用 lxml.etree 库来解决这个问题。
我见过的许多示例都有一个初始级别的命名空间,用于覆盖xmlns:xsi 部分的属性:
namespace_map = {
None: persona_namespace,
'xsi': "http://www.w3.org/2001/XMLSchema-instance"}
但是第二部分出现了两个问题xsi:schemaLocation
1) 如何使用 lxml 完成二级命名空间?
2) 如何允许命名空间包含空格而不收到错误 (http://worldcat.org/xmlschemas/IDMPersonas-2.2 IDMPersonas-2.2.xsd)
【问题讨论】:
标签: python lxml xml-namespaces