Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #29878

Re: Editing Inkscape SVG files with Python?

From Ben Finney <ben+python@benfinney.id.au>
Subject Re: Editing Inkscape SVG files with Python?
Date 2012-09-24 11:02 +1000
References <505f92f7$0$1612$c3e8da3$76491128@news.astraweb.com>
Newsgroups comp.lang.python
Message-ID <mailman.1172.1348448589.27098.python-list@python.org> (permalink)

Show all headers | View raw


Steven D'Aprano <steve+comp.lang.python@pearwood.info> writes:

> I have some SVG files generated with Inkscape containing many text
> blocks (over 100). I wish to programmatically modify those text blocks
> using Python. Is there a library I should be using, or any other
> guidelines or advice anyone can give me?

My first step would be to use ‘lxml’ to manipulate an XML tree, since
that's what an SVG document contains.

Read the SVG file as a text string, de-serialise the text to an XML
tree. Match the nodes of interest using an XPath query, iterate over
them. Change the content of each node using Python text manipulation,
set the new value on the node. Re-serialise the tree to the SVG file.

-- 
 \       “I distrust those people who know so well what God wants them |
  `\    to do to their fellows, because it always coincides with their |
_o__)                      own desires.” —Susan Brownell Anthony, 1896 |
Ben Finney

Back to comp.lang.python | Previous | NextPrevious in thread | Next in thread | Find similar | Unroll thread


Thread

Editing Inkscape SVG files with Python? Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2012-09-23 22:53 +0000
  Re: Editing Inkscape SVG files with Python? Ben Finney <ben+python@benfinney.id.au> - 2012-09-24 11:02 +1000
  Re: Editing Inkscape SVG files with Python? Matej Cepl <mcepl@redhat.com> - 2012-09-24 08:06 +0200

csiph-web