Beefy Boxes and Bandwidth Generously Provided by pair Networks
Welcome to the Monastery

Simple modification to SVG

by Anonymous Monk
on Sep 04, 2013 at 05:57 UTC ( #1052218=perlquestion: print w/replies, xml ) Need Help??
Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:

I've got a script that generates fairly complicated reports using SVGs as templates. The "master" template is an SVG that contains pointers to additional SVGs that provide the content for the report. These SVGs are generated programatically. The point of the master is to layout the content SVGs on the page. To make editing easy, I use a master template that contains colored boxes instead of links to images. Currently I convert the master template manually. I would like to automate this. How can I replace each line in the template:

<rect x="36" y="36" fill="#0000FF" width="392.4" height="43.2"/>


<image overflow="visible" width="392.4" height="43.2" xlink:href="0000FF.svg" transform="matrix(1 0 0 1 36 36)"></image> ? Additionally, for one particular box, specified by a certain fill color, I would like to read the height so that I can use this to adjust how part of the image generation script functions.

Replies are listed 'Best First'.
Re: Simple modification to SVG
by kcott (Chancellor) on Sep 04, 2013 at 10:50 UTC

    SVG is an XML application. Choose a module that can manipulate XML files and perform the necessary changes.

    The module you pick may be dependent on what you're familiar with. I'd probably choose XML::LibXML because that's what I'm familiar with. You can search CPAN for modules in the XML:: namespace: there's a lot to choose from (and not all of them applicable to your current requirements).

    From the limited information you've provided regarding the replacement, it appears that certain rect element attribute values need to be used (possibly after some manipulation) as image element attribute values. This looks straightforward, e.g. $href = substr($fill, 1) . '.svg', but come back and ask if you run into difficulties. [To get the best answers, follow the guidelines in "How do I post a question effectively?"]

    -- Ken

Re: Simple modification to SVG
by choroba (Chancellor) on Sep 04, 2013 at 06:28 UTC
    As an Anonymous Monk, you cannot edit your previous related questions. You can still link to them, though.
    لսႽ ᥲᥒ⚪⟊Ⴙᘓᖇ Ꮅᘓᖇ⎱ Ⴙᥲ𝇋ƙᘓᖇ

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://1052218]
Approved by kcott
and all is quiet...

How do I use this? | Other CB clients
Other Users?
Others making s'mores by the fire in the courtyard of the Monastery: (6)
As of 2017-06-28 23:32 GMT
Find Nodes?
    Voting Booth?
    How many monitors do you use while coding?

    Results (652 votes). Check out past polls.