xmlgraphics-batik-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Thomas DeWeese <thomas.dewe...@gmail.com>
Subject Re: Unable to output DOM document into SVG/XML format
Date Fri, 25 Nov 2011 14:31:14 GMT
Hi Alan,

On Nov 24, 2011, at 9:16 PM, Alan Pandit <alan.pandit@gmail.com> wrote:

> I am attempting to output the contents of a DOM Tree in XML format to System.out using
the SVGGraphics2D class.  Essentially, I want to be able to see what tags I am creating as
I perform calls to appendChild(), but when I execute the code below, I don't see "Hello World"
or <text> as I expect to see.  Are the calls to appendChild() supposed to change the
Document object named doc so the changes will be reflected in the streamed out SVG?

   Yes and no respectively.  The calls to appendChild will modify 'doc' but the SVGGraphics2D
doesn't stream out 'doc', it builds it's own DOM tree that it streams out (it uses the document
you pass it as a factory for the elements in the Dom tree it builds).  You can get the tree
it has written by calling getRoot() see it's JavaDoc for more info.

> 
>         String svgNS = SVGDOMImplementation.SVG_NAMESPACE_URI;
>         DOMImplementation impl = SVGDOMImplementation.getDOMImplementation();
>         Document doc = impl.createDocument(svgNS, "svg", null);
>                 
>         Element svgRoot = doc.getDocumentElement();
>         
>         Element e = doc.createElement("text");

   As was mentioned already this should be 'createElementNS' with the SVG namespace.

>         svgRoot.appendChild(e);
>         
>         Text t = doc.createTextNode("Hello World");
>         
>         svgRoot.appendChild(t);

     You probably want to append this to 'e'.

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


Mime
View raw message