1
我正在操作ElementTree中的SVG文件。鑑於該文件test.svg
在ElementTree中添加前綴屬性
<?xml version='1.0' encoding='utf-8'?>
<svg
xmlns="http://www.w3.org/2000/svg"
xmlns:xlink="http://www.w3.org/1999/xlink">
</svg>
我試圖與特定前綴創建一個元素
import xml.etree.ElementTree as ET
ET.register_namespace("", "http://www.w3.org/2000/svg")
tree = ET.parse('test.svg')
tree.getroot().set("xmlns:xlink", "http://www.w3.org/1999/xlink")
link = ET.fromstring('<a xlink:href="http://www.mysite.com/"></a>')
tree.write('worldMap/test_out.svg', encoding = 'utf-8', xml_declaration = True)
但碰上unbound prefix
錯誤。我已經通過this tutorial看過,但不能完全看到有什麼問題。
所以什麼問題? – enginefree