Re: How To Create a SVG-File in JAVA?

Bernd,

If what you are doing is simply generating SVG code (e.g., on a server)
for rendering later on in a browser, you could do something like (using
Project X, but you could also use Xerces):

import com.sun.xml.tree.*;
import org.w3c.dom.*;

XmlDocument doc = new XmlDocument();

Element svg = doc.createElement("svg");
Element rect = doc.createElement("rect");
rect.setAttribute("width", "400");
rect.setAttribute("width", "400");
svg.appendChild(rect);
doc.appendChild(svg);

// ....


// Stream to file
doc.write(new FileOutputStream("mySvgFile.svg"));

This does not give you the ease of use of the SVG Java bindings, but
it may be enough for what you are trying to do.

I hope this helps. FYI, we (Sun) are also working on a Java 2D API 
Graphics2D SVG generator that would automatically translate any Java 
rendering into its SVG equivalent, but this is not yet available on 
Sun's web site.

Regards.
V.

Bernd Grolig wrote:
> 
> Hi,
> 
> I'm new to programming in Java. For an application (for my graduation work),
> I want to generate a SVG File containing geographical Inormation.
> 
> For this, I want to use the JavaBinding for SVG and therefor the
> Implemenation from the SVG Toolkit from Csiro (www.csiro.org).
> 
> My question:
> I'm not sure how to start, creating the FileBuffer in Java using the methods
> in provided by the W3C-SVG JavaBinding and the Csiro SVG Toolkit.
> Is there anybody who could post an example. It's just to get an idea of how
> this works.
> 
> Thanks for every idea.
> 
> Regards, Bernd.

Received on Tuesday, 30 May 2000 13:29:13 UTC