Hi, Apologies, I didn't see this post earlier: http://www.nabble.com/Reg%3A-Accessing-SVG-DOM-tree-using-Java-to867651.html#a879225. The example given there clarified for me what Thomas meant by evaling the text content of script nodes. For the workaround I wasn't getting that the script nodes actually contain the script. I'm working with script elements that link to javascript files and wasn't understanding how you would evaluate a link.
I ended up using the approach given at http://mcc.id.au/2007/09/batik-course/, section 45 "Evaluating Script from Java", in the following way. Note: when I used getElementsByTagNameNS as suggested in the workaround it didn't return any elements. // After adding a subtree to the main svg document any scripts // in the subtree are evaluated NodeList nScript = doc.getElementsByTagName("script"); FileReader scriptReader; String path; for (int i = 0; i < nScript.getLength(); i++) { // skip the first one as it's the script from the original svg doc if (i > 0) { try { path = ((Element) nScript.item(i)).getAttributeNS("http://www.w3.org/1999/xlink", "href"); // strip "file:" path = path.substring(5); scriptReader = new FileReader(path); canvas.evaluateInES(scriptReader); // the extended JSVGCanvas } catch (Exception ex) { ex.printStackTrace(); } } } Regards, Jeff Cressman jeff.cressman wrote: > > Hi Thomas, > > I am writing similar code where I want to add svg elements containing > script elements to a previously loaded document. I don't quite understand > the workaround. If you could explain it in a little more detail I would be > grateful. Are you suggesting that the new subtree gets searched from a > script loaded with the original document or from the java code that adds > the subtree? Once the script elements are identified I don't understand > what is meant by "eval"ing them. If my script element is <script > xlink:href="circle.js"/> then do I eval the whole element or just the > xlink:href="circle.js" portion? > > Thanks, > Jeff Cressman > > > thomas.deweese wrote: >> >> >> BTW you can probably fix this in your script by searching the >> 'too be added' subtree for script elements (getElementsByTagNameNS) >> and simply "eval"ing the text content of them (I say simply but >> the text content is likely split across multiple text nodes). >> Anyway it's a potential workaround if you need one. >> >> > > -- View this message in context: http://www.nabble.com/svg%3Ascript-error...-tp5380680p15079154.html Sent from the Batik - Users mailing list archive at Nabble.com. --------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
