Thank you, it works fine! I will keep those routine somewhere....
On Wed, Dec 30, 2009 at 7:16 PM, jonathan wood
<[email protected]>wrote:
> Hi Dao,
>
> Here are a couple of load routines I use frequently .. Hope they help you
> narrow your problem.
>
> Load from a file on the classpath (templated)
>
> InputStream templateStream =
> Canvas.class.getResourceAsStream("template.svg");
> String parser = XMLResourceDescriptor.getXMLParserClassName();
> SAXSVGDocumentFactory f = new SAXSVGDocumentFactory(parser);
> SVGDocument doc = null;
>
> try {
> doc = f.createSVGDocument(null, templateStream);
> } catch (IOException ex) {
> }
>
> myCanvas.setSVGDocument(doc);
>
>
> Load from a byte array version:
>
> Element a = null;
> ByteArrayInputStream bais = new
> ByteArrayInputStream(myByteArray);
> String parser =
> XMLResourceDescriptor.getXMLParserClassName();
> SAXSVGDocumentFactory f = new
> SAXSVGDocumentFactory(parser);
>
> try {
> a = f.createDocument(null, bais).getDocumentElement();
> } catch (IOException ex) {
> }
>
> a = (Element) document.importNode(a, true);
>
>
>
>
>
> On Wed, Dec 30, 2009 at 12:47 PM, dao <[email protected]> wrote:
>
>> hello, I am stucked in the process of creating a JSVGCanvas from a SVG XML
>> content coming from an input stream.
>>
>> What is the best practice?
>>
>> Here is the way I do that:
>>
>> DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
>>
>> DocumentBuilder builder = factory.newDocumentBuilder();
>>
>> String xmlDocument = remoteEngine.getSvgDocument();
>>
>> System.out.println(xmlDocument);
>>
>> InputStream inStream = new ByteArrayInputStream(xmlDocument.getBytes());
>>
>> return builder.parse(inStream);
>>
>>
>> I get into a ClassCastEexception when batik tries to narrow the document
>> to a SVG document (I suppose so...)
>>
>> --
>> Dao Hodac
>>
>
>
--
Dao Hodac