views:

4621

answers:

5

Hi,

I'm trying to create some mixed HTML/SVG content and having some trouble. The HTML content shows up as expected, but the inline SVG does not. So, I do some experiments.

I find sites which have examples of inline SVG, and they render correctly on my system. So, I "view page source" and copy/paste the HTML/SVG into another local file, and open this file in Firefox. No inline SVG is visible.

I also tried the same experiment with Chrome, same results.

What might I be missing?

Update
Slight change in identity on my part: k montgomery -> kmontgom on use of OpenID.

Anyway thanks to all those who answered. The best solution was in setting the Response.ContentType; this lets me continue on with the WebForms approach for now.

I had contemplated making pure XHTML content in .xml files and using ASP.NET MVC to serve up that content. I may end up doing that in the future.

Now, onward with jQuery, SVG, and making the thing do something.

Thanks for all the help.

+5  A: 

Make sure to name the file ".xml" not ".html"

Greg
Thanks! That works. Now the next question is how to make ASP.NET generate a .XML file instead of .HTM or .HTML
'fraid I don't know the answer to that one
Greg
k montgomery, I guess you can set a mime-type header, see my reply for details.
Sergey Ilinsky
Thanks for this tip. I spent an entire day trying to make this work. Even setting a meta content=application/xhtml+xml didn't work.
Xymor
Here is some more info on that. There's a differnet if the file is opened locally or if it is served.http://wiki.svg.org/Inline_SVG#Choosing_a_Filename_Extension
kioopi
+6  A: 

In order for inline SVG to be shown in browsers, the page must be XHTML valid and must be serverd with application/xhtml+xml mime-type server response header.

It is also possible to pull inline SVG content from HTML page as well, see an example of an SVG Tiger image that can also be viewed in Internet Explorer (5.5+)

Sergey Ilinsky
ASP.NET example: `Response.ContentType = "application/xhtml+xml"`
Jørn Schou-Rode
Note that this shouldn't be an issue in future versions of Firefox. See http://hsivonen.iki.fi/test-html5-parsing/
sdwilsh
+1  A: 

As Greg said, it needs to be a file that Firefox recognises as an XHTML file, not just regular HTML, which is what that renaming accomplished. In order to get that from a server-side app, you need to set the response's Content-type header to application/xhtml+xml.

Paul Fisher
A: 

Slight change in identity on my part: k montgomery -> kmontgom on use of OpenID.

Anyway thanks to all those who answered. The best solution was in setting the Response.ContentType; this lets me continue on with the WebForms approach for now.

I had contemplated making pure XHTML content in .xml files and using ASP.NET MVC to serve up that content. I may end up doing that in the future.

Now, onward with jQuery, SVG, and making the thing do something.

Thanks for all the help.

kmontgom
+1  A: 

An alternative if you don't want to do XHTML is to base64 encode the SVG data.

e.g.

<object type="image/svg+xml" 
        data="data:image/svg+xml;base64,PCFET0NUWVBFI...etc..."></object>

I think this is probably not what you want specifically for your situation, but anyway, may be useful for others.

idij