[jdom-interest] SAXOutputter seems to be ignoring namespace

Dinkar Ganti dinkarg at lifeconnect.com
Fri Aug 17 11:10:45 PDT 2001


This may be a known issue or maybe I am doing something wrong. I generate an
SVG document and use JDOM for generating the XML. When I use XMLOutputter in
a stand-alone application, the browser is able to read the SVG document
properly. However, when I am running the application through Cocoon, the
browser complains "SVG root element in unknown namespace. No image drawn"
Snippet of the html source ...

<svg stroke-dasharray="none" shape-rendering="auto" font-family="'Arial'"
text-rendering="auto" fill-opacity="1" contentScriptType.....


Is this a SAXOutputter or a Cocoon issue?



import java.awt.Rectangle;
import java.awt.Graphics2D;
import java.awt.Color;
import java.io.Writer;
import java.io.OutputStreamWriter;
import java.io.IOException;
import org.apache.batik.svggen.SVGGraphics2D;
import org.apache.batik.dom.GenericDOMImplementation;
import org.apache.batik.dom.svg.SVGDOMImplementation;
import org.w3c.dom.Document;
import org.w3c.dom.DOMImplementation;

import java.util.List;

import org.jdom.Document;
import org.jdom.Element;
import org.jdom.JDOMException;
import org.jdom.Namespace;
import org.jdom.input.DOMBuilder;
import org.jdom.output.XMLOutputter;
import org.jdom.output.SAXOutputter;
import org.xml.sax.ContentHandler;

public class SVGTest {

    public void paint(Graphics2D g2d) {
        g2d.fill(new Rectangle(10, 10, 100, 100));

    public static void main(String [] args) throws IOException {

        // Get a DOMImplementation
        DOMImplementation domImpl =

        // Create an instance of org.w3c.dom.Document
        org.w3c.dom.Document document = domImpl.createDocument(null, "svg",

        // Create an instance of the SVG Generator
        SVGGraphics2D svgGenerator = new SVGGraphics2D(document);

        // Ask the test to render into the SVG Graphics2D implementation
        SVGTest test = new SVGTest();

        // Finally, stream out SVG to the standard output using UTF-8
        // character to byte encoding
	//        boolean useCSS = true; // we want to use CSS style attribute
        //Writer out = new OutputStreamWriter(System.out, "UTF-8");
        //svgGenerator.stream(out, useCSS);

	org.w3c.dom.Element svgRoot = svgGenerator.getRoot();
	Namespace ns = Namespace.getNamespace("svg",
	DOMBuilder builder = new DOMBuilder();

	XMLOutputter outputter = new XMLOutputter();
	org.jdom.Document jdomDocument = builder.build(document);
	org.jdom.Element rootJDOMElement = jdomDocument.getRootElement();
	rootJDOMElement.setAttribute("svg","svg", ns);
	outputter.output(jdomDocument, System.out);

	//outputter.output(builder.build(svgGenerator.getRoot()), System.out);

More information about the jdom-interest mailing list