我正在使用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')
Run Code Online (Sandbox Code Playgroud)
这会生成输出:
<?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>
Run Code Online (Sandbox Code Playgroud)
这不会解析为有效的SVG.如何删除ns0名称空间?
jfe*_*ick 49
我只是想出来了,我不能删除这个问题,所以这里是:
etree.register_namespace("","http://www.w3.org/2000/svg")
Run Code Online (Sandbox Code Playgroud)
我认为这只适用于Python 2.7.
| 归档时间: |
|
| 查看次数: |
7644 次 |
| 最近记录: |