python编辑svg文件_在svg文件中使用python搜索和更改文本

I've a SVG file created with Inkscape, now in the svg file is some text i try to alter but how?

The svg looks like this:

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">

...

inkscape:groupmode="layer"

inkscape:label="05_CURVES"

id="g4182"

transform="translate(0,-322.51962)"

style="display:inline">

...

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">

sodipodi:role="line"

id="tspan5025-6-2-1-0"

x="82.288353"

y="920.41907"

style="font-size:32px">TEXT TO CHANGE

...

I tried using xml.etree.ElementTree didn't get to the TEXT TO CHANGE...

I also tried

from xml.dom as minidom

doc = minidom.parse('File.svg')

text = [text.getAttribute('id') for text in doc.getElementsByTagName('text')

but i didn't get to the TEXT TO CHANGE...

how can I alter the text

解决方案

TEXT TO CHANGE is in tspan tag

import xml.dom.minidom

doc = xml.dom.minidom.parse('File.svg')

name = doc.getElementsByTagName('tspan')

for t in name:

if (t.attributes['id'].value=="tspan5025-6-2-1-0"):

print [x.nodeValue for x in t.childNodes]

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值