Beefy Boxes and Bandwidth Generously Provided by pair Networks
Problems? Is your data what you think it is?

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.

Comment on Simple modification to SVG
Replies are listed 'Best First'.
Re: Simple modification to SVG
by kcott (Canon) 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 (Canon) 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 the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others romping around the Monastery: (5)
As of 2015-11-29 08:40 GMT
Find Nodes?
    Voting Booth?

    What would be the most significant thing to happen if a rope (or wire) tied the Earth and the Moon together?

    Results (749 votes), past polls