xmlgraphics-batik-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Phillip Larsen" <phillip.lar...@intermedium.no>
Subject Changing nodes in SVG DOM-tree
Date Fri, 11 Jan 2002 09:07:58 GMT
Hi everyone,
I've got a problem trying to change the contents of the SVG DOM-tree that is
created with the svggen module of Batik after I've done some drawing
in Java2D using the SVGGraphics2D class as input to my Java2D drawing

I know that the drawing routines creates the SVG-document fine when I dont
try to alter
the contents of the DOM-tree as I am able to render the unaltered SVG

The problem is that I want to add some <a xlink:href="link here"> links to
the circles that
I am drawing. I am creating a graph where I want the nodes in the graph to
be clickeable.

What I try to do to alter the tree is the following :

//Here are my import statements
import org.apache.batik.svggen.SVGGraphics2D;
import org.apache.batik.svggen.SVGSyntax;
import org.apache.batik.svggen.XmlWriter;
import org.apache.batik.dom.*;
import org.apache.batik.dom.traversal.DOMNodeIterator;
import org.w3c.dom.*;
import org.w3c.dom.traversal.NodeFilter;

import org.apache.batik.util.XMLConstants;
import org.apache.batik.ext.awt.g2d.AbstractGraphics2D;
import org.apache.batik.ext.awt.g2d.GraphicContext;

//Getting a DOMNodeIterator to traverse the nodes of the SVG DOM-tree.
svgGenerator is of class SVGGraphics2D.
DOMNodeIterator dniterator = new DOMNodeIterator((AbstractDocument)

//Declaring a node nodeindoc
Node nodeindoc;

//Declaring a node parentnode, which will act as the parent for the
nodeindoc in the DOM-tree traversal
Node parentnode;

//Declaring an element elementnode.
Element elementnode;

//Creating a DocumentFragment to hold the elementnode and its child.
DocumentFragment df;

df = svgGenerator.getDOMFactory().createDocumentFragment();

//Setting the node nodeindoc equal to the first element in the
nodeindoc = dniterator.nextNode();
while(nodeindoc != null)
   if(nodeindoc.getNodeType() == Node.ELEMENT_NODE)
    if(((Element) nodeindoc).getTagName() == SVGSyntax.SVG_CIRCLE_TAG)
     //Creating the elementnode as part of the document holding the SVG-DOM
     //If the nodeindoc node points to an element that is a circle,
     //I will append the circle to this elementnode, trying to create a
circle node with a link.

     elementnode =


     //Setting the nodeindoc as a child of the elementnode, and elementnode
as child of the documentfragment.
     //Getting the parent node of nodeindoc, replacing nodeindoc with the
nodes of the documentfragment
     parentnode = nodeindoc.getParentNode();
     parentnode = null;
     df = null;
   nodeindoc = dniterator.nextNode();

  //Creating an output stream that will be used to stream out the contents
of the svgGenerator to a web-page.
  boolean useCSS = false;
  Writer svgOutPutStream = new OutputStreamWriter(out, "UTF-8");

  //finally I stream the contents of the svgGenerator out to the output

  The problem is however that after I have done this none of my circles have
any <a> tags attached to them, and more often than not
  the program hangs when I try to append the nodeindoc to the elementnode.
  Does anyone have any input as to how I can manipulate the contents of the
SVG DOM-tree after it has been created and stream
  out circles with links attached to them I would be very grateful for any


  Thankyou in advance
  Yours sincerely
   Phillip Larsen

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

View raw message