我在使用lxml生成的SVG文件中有一个文本元素。我想在这个元素中保留空格。我创建了文本元素,然后尝试将xml:space .set()到preserve,但似乎都不起作用。我可能在概念上漏掉了一些东西。有什么想法吗?
发布于 2013-07-05 03:47:27
您可以通过显式指定与特殊xml:前缀关联的名称空间URI (请参见http://www.w3.org/XML/1998/namespace)来完成此操作。
from lxml import etree
root = etree.Element("root")
root.set("{http://www.w3.org/XML/1998/namespace}space", "preserve")
print etree.tostring(root)输出:
<root xml:space="preserve"/> https://stackoverflow.com/questions/17476749
复制相似问题