To capitalized this mailing list thread :

canvas = new JSVGCanvas();


  • private Document createDoc() throws ParserConfigurationException,
                            RemoteException, SAXException, IOException {
            String xmlDocument = remoteEngine.getSvgDocument();
            ByteArrayInputStream bais = new ByteArrayInputStream(xmlDocument.getBytes());
            String parser = XMLResourceDescriptor.getXMLParserClassName();
            SAXSVGDocumentFactory f = new SAXSVGDocumentFactory(parser);
            return f.createDocument(DOC_URI, bais);

Note the DOC_URI constant. It helps the user to set up the URI of the document. If the document works from itself, in a standalone mode and does not refers to other relative paths, it can be set at null.

Else, it is necessary to put an URI that points to a non existant file so that the relative URI can be resolved.

For example, an SVG document that refers to a widgets.svg file in a tag like this one:

<use x="-53.175" y="-194.283" xmlns:xlink="" xlink:href="widgets.svg#BarGauge" xlink:type="simple" xlink:actuate="onLoad" id="bar2" height="388.566" xlink:show="embed"/>

should be set up with an URI that points on a file of the same directory as the widgets.svg file.

It is possible to use some jar file URL to point inside a jar (so you can embed symbols svg inside your jar):

  • No labels