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 Peter Hull <pe...@gmail.com> on 2010/04/07 13:16:55 UTC

Question about JSVGCanvas.setDocument()

Dear all,
I am trying to display a document which was created with a different
DOM implementation. The documentation seems to suggest this is
possible but I get an exception. Please could someone explain what's
happening?
Example code fragment:
Document d = DocumentBuilderFactory.newInstance().newDocumentBuilder().parse(FILENAME);
JSVGCanvas canvas = new JSVGCanvas();
canvas.setDocument(d);
and the exception is
 Exception in thread "main" java.lang.ClassCastException:
org.apache.batik.dom.GenericElement cannot be cast to
org.w3c.dom.svg.SVGSVGElement

Thanks
Peter

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


Re: Question about JSVGCanvas.setDocument()

Posted by Peter Hull <pe...@gmail.com>.
Dear Thomas,
Thank you for the swift reply. I modified the code to make my factory
namespace aware as follows:
DocumentBuilderFactory newInstance = DocumentBuilderFactory.newInstance();
newInstance.setNamespaceAware(true);
Document d = newInstance.newDocumentBuilder().parse(FILENAME);
JSVGCanvas canvas = new JSVGCanvas();
canvas.setDocument(d);
and that worked.
I did see those comments about namespaces in the FAQ but I didn't
think they applied in this case, so apologies for that.

Peter


On Wed, Apr 7, 2010 at 1:36 PM,  <th...@kodak.com> wrote:
> Hi Peter,
>
> Peter Hull <pe...@gmail.com> wrote on 04/07/2010 07:16:55 AM:
>
>> I am trying to display a document which was created with a different
>> DOM implementation. The documentation seems to suggest this is
>> possible but I get an exception. Please could someone explain what's
>> happening?
>
>> Example code fragment:
>> Document d =
>> DocumentBuilderFactory.newInstance().newDocumentBuilder().parse(FILENAME);
>
>     The main issue is, I think, that your XML parser is not configured
> to be namespace aware.  Without namespaces you end up with an
> 'svg' element that is not in the SVG namespace and consequently
> when we import your DOM for the canvas it ends up not being an
> SVGSVGElement - which means that it can't be displayed in the canvas.
>
>

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


Re: Question about JSVGCanvas.setDocument()

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

Peter Hull <pe...@gmail.com> wrote on 04/07/2010 07:16:55 AM:

> I am trying to display a document which was created with a different
> DOM implementation. The documentation seems to suggest this is
> possible but I get an exception. Please could someone explain what's
> happening?

> Example code fragment:
> Document d = 
DocumentBuilderFactory.newInstance().newDocumentBuilder().parse(FILENAME);

    The main issue is, I think, that your XML parser is not configured
to be namespace aware.  Without namespaces you end up with an
'svg' element that is not in the SVG namespace and consequently
when we import your DOM for the canvas it ends up not being an
SVGSVGElement - which means that it can't be displayed in the canvas.