2012年12月3日月曜日

Creating a Document from an SVG file

With Batik, you can also create an SVG DOM tree from a URI, an InputStream , or a Reader , using the SAXSVGDocumentFactory . The following example illustrates how to create an SVG document from a URI using the SAXSVGDocumentFactory class.


import java.io.IOException;

import org.apache.batik.dom.svg.SAXSVGDocumentFactory;
import org.apache.batik.util.XMLResourceDescriptor;

import org.w3c.dom.Document;

try {
String parser = XMLResourceDescriptor.getXMLParserClassName();
SAXSVGDocumentFactory f = new SAXSVGDocumentFactory(parser);
String uri = "http://www.example.org/diagram.svg";
Document doc = f.createDocument(uri);
} catch (IOException ex)
{ // ... }

As we have created an SVG Document , we can cast this document to an SVGDocument (defined in the org.w3c.dom.svg package) if needed.

0 件のコメント:

コメントを投稿