我有一个用 Inkscape 创建的 SVG 文件,现在 svg 文件中有一些我尝试更改的文本,但是如何更改呢?svg 看起来像这样:
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<svg
xmlns:dc="http://purl.org/dc/elements/1.1/"
xmlns:cc="http://creativecommons.org/ns#"
xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
xmlns:svg="http://www.w3.org/2000/svg"
xmlns="http://www.w3.org/2000/svg"
xmlns:xlink="http://www.w3.org/1999/xlink"
xmlns:sodipodi="http://sodipodi.sourceforge.net/DTD/sodipodi-0.dtd"
xmlns:inkscape="http://www.inkscape.org/namespaces/inkscape"
width="1480"
height="800"
version="1.1"
id="svg4184"
sodipodi:docname="2017-05-03_heizung2.svg"
inkscape:version="0.92.1 r15371">
...
<g
inkscape:groupmode="layer"
inkscape:label="05_CURVES"
id="g4182"
transform="translate(0,-322.51962)"
style="display:inline">
...
<text
xml:space="preserve"
style="font-style:normal;font-weight:normal;font-size:37.33333206px;line-height:1.25;font-family:sans-serif;letter-spacing:0px;word-spacing:0px;fill:#000000;fill-opacity:1;stroke:none"
x="82.288353"
y="920.41907"
id="temp-bu"><tspan
sodipodi:role="line"
id="tspan5025-6-2-1-0"
x="82.288353"
y="920.41907"
style="font-size:32px">TEXT TO CHANGE</tspan></text>
...
</g>
</svg>
Run Code Online (Sandbox Code Playgroud)
我尝试使用 xml.etree.ElementTree 没有到达要更改的文本...我也尝试过
from xml.dom as minidom
doc = minidom.parse('File.svg')
text = [text.getAttribute('id') for text in doc.getElementsByTagName('text')
Run Code Online (Sandbox Code Playgroud)
但我没有到达要更改的文本...
我怎样才能改变文字
永远不要忽视暴力所固有的可能性。
>>> open('newfile.svg', 'w').write(open('temp.svg').read().replace('>TEXT TO CHANGE</tspan>','>What I meant to write</tspan>'))
Run Code Online (Sandbox Code Playgroud)
结果: