You are viewing a plain text version of this content. The canonical link for it is here.
Posted to batik-users@xmlgraphics.apache.org by Miguel Bento <ni...@gmail.com> on 2008/08/31 00:58:31 UTC

Quick batik question

Hi everyone,

I was having a look at the Batik website and a few examples i found around
and couldn't find usefull info for what i want to do. I'm developing a GWT
drawing application that stores the content in svg and i'm trying to use
Batik to "read" the content.

The SVG content is stored as a string, passed as an argument, and i wanted
to use Batik to construct a GVT tree, so that i could then iterate the tree,
and construct the Graphic Objects in my application. Pretty simple.. but, i
only found examples using URI to construct the GVT tree.. so any
help/pointers would be appreciated.

Best Regards,
Miguel Bento.

Re: Quick batik question

Posted by Cameron McCormack <ca...@mcc.id.au>.
Hello Miguel.

Miguel Bento:
> The SVG content is stored as a string, passed as an argument, and i wanted
> to use Batik to construct a GVT tree, so that i could then iterate the tree,
> and construct the Graphic Objects in my application. Pretty simple.. but, i
> only found examples using URI to construct the GVT tree.. so any
> help/pointers would be appreciated.

To get an SVGDocument instance from your string, you’ll need to use the
SAXSVGDocumentBuilder class, like this, assuming ‘content’ has your SVG
content as XML:

  import org.apache.batik.dom.svg.SAXSVGDocumentFactory;
  import org.apache.batik.util.XMLResourceDescriptor;
  import java.io.StringReader;
  …
  String content = …;
  SAXSVGDocumentFactory f = new SAXSVGDocumentFactory(XMLResourceDescriptor.getXMLParserClassName());
  SVGDocument doc = f.createSVGDocument(null, new StringReader(content));

(Untested code, but should be the right approach.)  And once you have
the SVGDocument instance, you can do the stuff from your example to
build the graphics tree (using GVTBuilder).

-- 
Cameron McCormack ≝ http://mcc.id.au/

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