Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl-Sensitive Sunglasses

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 (Bishop) 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
[GotToBTru]: our beagle has dispatched 3 rabbits to the Great Hutch in the Sky since March.
[thezip]: I can always tell when the dogs have been mousing, as there is a concentric ring of mud around the end of their snouts when they do.
[thezip]: As for more physical evidence, that always seems to be missing somehow
[Rabbi Bob]: We have a Jack Russell: off the leash she is a torpedo against mice, rats, chipmunks and squirrels
[Rabbi Bob]: Doesn't eat them, just snaps, kills, drops and moves on.
[thezip]: Efficient, that one.
[erix]: my dog could do the classic mouse jump (never caught a mouse :)

How do I use this? | Other CB clients
Other Users?
Others about the Monastery: (14)
As of 2017-11-17 19:57 GMT
Find Nodes?
    Voting Booth?
    In order to be able to say "I know Perl", you must have:

    Results (272 votes). Check out past polls.