gpt4 book ai didi

python - 使用 Python 3 ElementTree 的 XML 文档中的多个命名空间

转载 作者:行者123 更新时间:2023-12-04 17:06:46 31 4
gpt4 key购买 nike

我正在尝试使用 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/

31 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com