You are viewing a plain text version of this content. The canonical link for it is here.
Posted to batik-users@xmlgraphics.apache.org by Joel Uckelman <uc...@nomic.net> on 2010/04/09 22:06:28 UTC

Batik and invalid SVG

Our application is fed invalid SVG from time to time; we'd like to be
able to handle that in a graceful way. For example, today I came across
some SVG containing this,

  <comment>rotation angles = -arctan(8/9)</comment>

which causes a DOMException because "comment" isn't a valid SVG element.
Now, lots of SVG viewers will still display the image because they can
ignore bad elements. Is there a way to get Batik to do this? (Or, is
there at least a guide to what exceptions can occur when reading SVG
so that we can catch them and notify the user that loading failed because
the SVG is bad? The DOMException I got took me completely by surprise,
since it's unchecked and not documented anywhere I've seen that a
DOMException can be thrown by SAXSVGDocumentFactory.createDocument().)

-- 
J.

---------------------------------------------------------------------
To unsubscribe, e-mail: batik-users-unsubscribe@xmlgraphics.apache.org
For additional commands, e-mail: batik-users-help@xmlgraphics.apache.org


Re: Batik and invalid SVG

Posted by th...@kodak.com.
Hi Joel,

Joel Uckelman <uc...@nomic.net> wrote on 04/09/2010 04:06:28 PM:

> Our application is fed invalid SVG from time to time; we'd like to be
> able to handle that in a graceful way. For example, today I came across
> some SVG containing this,
> 
>   <comment>rotation angles = -arctan(8/9)</comment>
> 
> which causes a DOMException because "comment" isn't a valid SVG element.
> Now, lots of SVG viewers will still display the image because they can
> ignore bad elements. Is there a way to get Batik to do this?

    I think the simplest way to achieve this would be to subclass our
SVGDOMImplementation and replace the createElementNS method with one
that does not throw an error for unknown elements in the SVG Namespace.

> (Or, is there at least a guide to what exceptions can occur when reading 

> SVG so that we can catch them and notify the user that loading failed 
> because the SVG is bad? The DOMException I got took me completely by 
> surprise, since it's unchecked and not documented anywhere I've seen 
that 
> a DOMException can be thrown by SAXSVGDocumentFactory.createDocument().)

        I don't believe such a guide exists.