An alternate out method from Document -> xml ... exceptions and proper variable init removed...the following get's you the same place

            DOMUtilities.writeDocument(doc, new FileWriter("myfile.svg"));

On Fri, Nov 25, 2011 at 2:08 AM, jonathan wood <> wrote:
I noticed a couple things, but am not where I can currently compile/test....

Create the TextElement in the SVG namespace

Change ...

        Element e = doc.createElement("text");

        Element e = doc.createElementNS(svgNS, "text");

... append the text to the textEl...




On Thu, Nov 24, 2011 at 9:16 PM, Alan Pandit <> 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?

        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");
        Text t = doc.createTextNode("Hello World");
        // Create an instance of the SVG Generator.
        SVGGraphics2D svgGenerator = new SVGGraphics2D(doc);

            // Finally, stream out SVG to the standard output using
            // UTF-8 encoding.
            boolean useCSS = true; // we want to use CSS style attributes
            Writer out = new OutputStreamWriter(System.out, "UTF-8");
  , useCSS);
        catch(Exception exc) {

This is the OUTPUT I get:

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE svg PUBLIC '-//W3C//DTD SVG 1.0//EN'
<svg style="stroke-dasharray:none; shape-rendering:auto; font-family:&apos;Dialog&apos;; text-rendering:auto; fill-opacity:1; color-interpolation:auto; color-rendering:auto; font-size:12; fill:black; stroke:black; image-rendering:auto; stroke-miterlimit:10; stroke-linecap:square; stroke-linejoin:miter; font-style:normal; stroke-width:1; stroke-dashoffset:0; font-weight:normal; stroke-opacity:1;" xmlns="" contentScriptType="text/ecmascript" preserveAspectRatio="xMidYMid meet" xmlns:xlink="" zoomAndPan="magnify" version="1.0" contentStyleType="text/css"
><!--Generated by the Batik Graphics2D SVG Generator--><defs id="genericDefs"/><g/></svg>