Baz has asked for the wisdom of the Perl Monks concerning the following question:

Hi,
i'm using the code below to fill a svg template, and send it to the client. The problem is that the svg is not being diplayed by the client-side browser (IE6) - and when I try it in Netscape, it starts downloading as a file. If I click veiw>>source in IE, the svg source is displayed perfectly (after it has been downloaded - it will say Done even before its actually finished), but normally you right click in the browser window to view the source and the veiw>>source option would be disabled.
This is my first time displaying svg from the server - normally I open my *.svg docs from my PC and the browser handles them fine - Is it the cgi extention thats causing the problems?
Thanks.
Heres the exe
#!/usr/bin/perl -w use strict; my @colors = ( [167,45,37,56,65,67,56,78,231,35,142,20,187,137,19,107 +,117,127,137], # ... [221,245,237,0,0,0,0,0,235,235,145,220,218,146,194,46, +133,127,45,32] # ... ); print "Content-type: image/svg+xml\n\n"; open DATA, '<g3.svg' or die $!; local $" = ','; # localise $" ($LIST_SEPARATOR) and set it to b +e a comma s/^var colors(\d+) = \[\];/var colors$1 = "[@{ $colors[$1 - 1] }]";/ and print # and print it if it matched or print # otherwise just print them while <DATA>; close DATA or warn $!;

Replies are listed 'Best First'.
Re: Sending SVG to Client
by dws (Chancellor) on Aug 25, 2002 at 00:20 UTC
    The problem is that the svg is not being diplayed by the client-side browser (IE6) - and when I try it in Netscape, it starts downloading as a file. If I click veiw>>source in IE, the svg source is displayed perfectly

    Sounds like a either a MIME type problem (in the code above) or a DOCTYPE problem (in g3.svg). The MIME type (Content-type: header) looks O.K.

    I'm not familiar with SVG, but were I in your position, I'd try using SVG.pm to generate some sample SVG, and would examine the Content-type: header and the <!DOCTYPE> tag that that it emits.

    Also, verify that you have a correct <?xml ...> tag.

      I tried this -
      http://baz.perlmonk.org/svg.cgi?ielikes=.svg
      and it works - should I settle with this, or is there something else I could do...as a matter of interest. I'm also not very happy with the way it behaves when its downloading (im on a 56K) - the download progress status bar disappears. On Netscape, a little window opens up and the file is downloaded, it then gives the Lauach option but launches it in IE - maybe thats normal, but i downloaded the plugins for both browsers.
        The current Adobe SVG Viewer does not work in Netscape. The plugin architecture changed and the Adobe team has not released a new build, yet. A previous build of Mozilla has SVG support built in.

        I suggest checking your mime types to ensure that image/svg+xml (I think) is in there.
Re: Sending SVG to Client
by fglock (Vicar) on Aug 25, 2002 at 02:07 UTC

    If it works when you put ".svg" at the end, you could also try using the header "Content-disposition:" with a "filename=xxx.svg" option.

      cool that works too, thanks.
Re: Sending SVG to Client
by BrowserUk (Patriarch) on Aug 25, 2002 at 05:25 UTC

    Baz, I'm not sure how relevant this is to your problem, and I should mention up front I haven't managed to get my browser (Opera6) to display Adobe's svg test samples yet!

    However, whilst I was trying to get this going, I was looking at the mime-type associations within Opera and noticed that extentions svg and svgz are associated with mime-type image/svg-xml rather than image/svg+xml as you are using in your header?

    Maybe changing this would prompt the plug-in to handle the inbound datastream (or at least be given the chance to by the browser).

    Unfortunately, the adobe install is a 'click'n'pray' affair giving no feedback on what it is doing leaving me with the task of trying to work this out what it did after-the-fact.

    Good luck. I think what your doing is really interesting. You don't have a svg file of the mainland by any chance do you:)


    What's this about a "crooked mitre"? I'm good at woodwork!
      Hi BrowserUK,

      I tried using -xml, but it behaved in the same way as the +xml. Anyway when I use "Content-Disposition" it stops IE from downloading the file.

      When you said mainland, I first thought you meant Europe, but your username suggests your referring to Britain. Anyway, I do plan to do Britain at a later stage, but in pieces - you’ve got a crazy population density over there (my project is here if your interested). Anyway, if you’re looking for an SVG map, get yourself "IMS Web Dwarf". It converts bitmaps to SVG.

      Thanks,
      Barry.