【问题标题】:Multiple namespaces in XML doc using Python 3 ElementTree使用 Python 3 ElementTree 在 XML 文档中的多个命名空间
【发布时间】:2018-09-12 09:31:31
【问题描述】:

我正在尝试使用 ElementTree 创建 XML 文档。该文档需要多个命名空间,但我在文档或在线找不到任何信息如何正确执行此操作。我需要顶行有 3 个命名空间,如下所示:

fu01:页面 xmlns:xsi="website1" xmlns:fu01="website2" xsi:schemaLocation="website3">

现在我有:

top = ET.Element("fu01:Page")
top.set("xmlns:xsi", "website1")

打印出第一个命名空间,但我不知道如何将其他两个也放入其中。

提前致谢!

【问题讨论】:

标签: python xml namespaces elementtree


【解决方案1】:

找到适合我的解决方案。

使用attrib 属性:

top.attrib["hello"] = "hi"

这会将该属性添加到元素中。

【讨论】:

    猜你喜欢
    • 2020-10-17
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-07-08
    • 1970-01-01
    • 2011-04-23
    • 2013-01-28
    相关资源
    最近更新 更多