xmlgraphics-batik-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From thomas.dewe...@kodak.com
Subject RE: Parsing SVG and grouping actions
Date Sat, 12 Apr 2008 17:21:15 GMT
Hi Keywan,

Keywan Najafi Tonekaboni <lists@prometoys.net> wrote on 04/12/2008 
09:25:49 AM:

> I deleted SVGGraphics2D from my code and try it now with DOM. I have the
> famous problem, that the JSVGCanvas didn't update. 

>    String svgNS = SVGDOMImplementation.SVG_NAMESPACE_URI;
>    Element g = doc.createElement("g");
>    Element image = doc.createElement("image");

   Your createElement calls need to be createElementNS
with the SVG Namespace:

        Element g = doc.createElementNS(svgNS, "g");
>    Element image = doc.createElementNS(svgNS,"image");

>    image.setAttribute("id", "ScannedDocument");

    To be technically correct this should be

        image.setAttributeNS(null, "id", "ScannedDocument");

>    image.setAttribute("xmlns:xlink","http://www.w3.org/1999/xlink");

      This isn't really correct it should be:
        String xlinkNS = "http://www.w3.org/1999/xlink";
        image.setAttributeNS(xmlNS, "xmlns:xlink", xlinkNS);

>    image.setAttribute("xlink:href",pngBase64);

        And this should be:
        image.setAttributeNS(xlinkNS, "xlink:href",pngBase64);

> I don't run it in the UpdateManager, because at this state JSVGCanvas
> don't has any Document associated and so no Update Manager is available.
> This is correct, or?

   Correct, the problem is that you were adding elements that weren't
SVG elements (because they aren't in the SVG namespace) so the document
ignored the added elements.

> Another question is about Document.getElementById()
> Can I use it with SVGDocument? When I do this, I got a
> NullPointerException:

   Probably because unless the elements are SVG element's the
document can't tell that the 'id' attribute is of type #ID.

> When I want to remove a shape from the document, is it enough to grab
> the element and then call "doc.removeChild(element);"? 

    No, because doc is not the parent of 'element'.  you can
call element.getParentNode().removeChild(element)

View raw message