Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我希望在 xml.etree 中设置命名空间前缀。我在网上找到了 register_namespace(prefix, url) 但这抛出了“未知属性”。我也试过 nsmap=NSMAP 但这也失败了。我将不胜感激显示如何添加指定命名空间前缀的示例语法
register_namespace仅在 lxml 2.3 中引入(仍为测试版)
register_namespace
我相信您可以nsmap在创建元素时提供一个参数(带有前缀 uri 映射的字典),但我认为您不能为现有元素更改它。(元素上有一个.nsmap属性,但更改似乎不起作用。.prefix元素上还有一个属性,但这是只读的)
nsmap
.nsmap
.prefix