Path: csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!news.mixmin.net!feed.xsnews.nl!border-1.ams.xsnews.nl!newsfeed.xs4all.nl!newsfeed6.news.xs4all.nl!xs4all!post.news.xs4all.nl!not-for-mail Return-Path: X-Original-To: python-list@python.org Delivered-To: python-list@mail.python.org X-Spam-Status: OK 0.001 X-Spam-Evidence: '*H*': 1.00; '*S*': 0.00; 'python.': 0.02; 'subject:Python': 0.05; 'modify': 0.05; 'python': 0.09; 'iterate': 0.09; 'received:80.91': 0.09; 'received:80.91.229': 0.09; 'received:gmane.org': 0.09; 'received:list': 0.09; 'subject:files': 0.09; 'library': 0.15; 'blocks': 0.16; 'finney': 0.16; 'node.': 0.16; 'nodes': 0.16; 'query,': 0.16; 'received:80.91.229.3': 0.16; 'received:plane.gmane.org': 0.16; 'subject:Editing': 0.16; 'using,': 0.16; 'string,': 0.17; 'file.': 0.20; 'header:User-Agent:1': 0.26; 'tree': 0.27; 'header:X -Complaints-To:1': 0.28; "d'aprano": 0.29; 'node': 0.29; 'steven': 0.29; 'writes:': 0.29; 'file': 0.32; 'anyone': 0.33; 'to:addr :python-list': 0.33; 'me?': 0.33; 'text': 0.34; 'ben': 0.35; 'subject:?': 0.35; 'there': 0.35; 'received:org': 0.36; 'subject:with': 0.36; 'should': 0.36; 'xml': 0.37; 'subject:: ': 0.38; 'files': 0.38; 'some': 0.38; 'advice': 0.39; 'to:addr:python.org': 0.39; 'step': 0.39; 'header:Received:5': 0.40; 'containing': 0.61; 'first': 0.61; 'interest': 0.62; 'god': 0.66; 'wish': 0.70; 'contains.': 0.84; 'tree,': 0.84; 'fellows,': 0.91 X-Injected-Via-Gmane: http://gmane.org/ To: python-list@python.org From: Ben Finney Subject: Re: Editing Inkscape SVG files with Python? Date: Mon, 24 Sep 2012 11:02:55 +1000 References: <505f92f7$0$1612$c3e8da3$76491128@news.astraweb.com> Mime-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Gmane-NNTP-Posting-Host: rasputin.madmonks.org X-Public-Key-ID: 0xBD41714B X-Public-Key-Fingerprint: 9CFE 12B0 791A 4267 887F 520C B7AC 2E51 BD41 714B X-Public-Key-URL: http://www.benfinney.id.au/contact/bfinney-gpg.asc X-Post-From: Ben Finney User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/23.4 (gnu/linux) Cancel-Lock: sha1:eMUH7bwX7Mu39GCU2X1m8hz2apA= X-BeenThere: python-list@python.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: General discussion list for the Python programming language List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Newsgroups: comp.lang.python Message-ID: Lines: 21 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1348448589 news.xs4all.nl 6856 [2001:888:2000:d::a6]:42010 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:29878 Steven D'Aprano 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