【发布时间】:2011-04-23 04:42:38
【问题描述】:
我正在 Python 2.7 中使用 ElementTree 构建一个 SVG 文档。代码如下:
from xml.etree import ElementTree as etree
root = etree.XML('<svg width="100%" height="100%" version="1.1" xmlns="http://www.w3.org/2000/svg"></svg>')
root.append(etree.Element("path"))
root[0].set("d", "M1 1 L2 2 Z")
print etree.tostring(root, encoding='iso-8859-1')
这会生成输出:
<?xml version='1.0' encoding='iso-8859-1'?>
<ns0:svg xmlns:ns0="http://www.w3.org/2000/svg" height="100%" version="1.1" width="100%"><path d="M1 1 L2 2 Z" /></ns0:svg>
这不会被解析为有效的 SVG。 如何删除 ns0 命名空间?
【问题讨论】: