使用Python ElementTree创建不带ns0名称空间的SVG/XML文档 [英] Create SVG / XML document without ns0 namespace using Python ElementTree

查看:320
本文介绍了使用Python ElementTree创建不带ns0名称空间的SVG/XML文档的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在Python 2.7中使用ElementTree构建SVG文档.这是代码:

I'm building an SVG document with ElementTree in Python 2.7. Here is the code:

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名称空间?

This does not parse as valid SVG. How can I remove the ns0 namespace?

推荐答案

我只是想出了办法,所以无法删除问题,所以这里是:

I just figured it out and I can't delete the question so here it is:

etree.register_namespace("","http://www.w3.org/2000/svg")

我认为这仅适用于Python 2.7.

I think this only works as of Python 2.7 though.

这篇关于使用Python ElementTree创建不带ns0名称空间的SVG/XML文档的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆