我正在尝试使用 ElementTree 创建一个 XML 文档。该文档需要多个命名空间,但我在文档或在线找不到如何正确执行此操作的任何信息。我需要顶行有 3 个命名空间,如下所示:
fu01:Page xmlns:xsi="website1" xmlns:fu01="website2" xsi:schemaLocation="website3">
现在我有:
top = ET.Element("fu01:Page")
top.set("xmlns:xsi", "website1")
它打印出第一个命名空间,但我不知道如何将另外两个命名空间也放入其中。
提前致谢!
最佳答案
找到了适合我的解决方案。
使用 attrib
属性:
top.attrib["hello"] = "hi"
这会将该属性添加到元素中。
关于python - 使用 Python 3 ElementTree 的 XML 文档中的多个命名空间,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49623585/