Hi Badreddine.
badreddine lakhlifi:
> i would like to know if there is a way(a method...) to add an element to an
> SVGDocument when the element is given as a string of SVG code.
>
> for example:
> String Code = "<polygon fill=\"none\" points=\"240.0, 243.0,.........\"
> stroke =\"#000000\"/>"
> SVGDocument doc = mycanvas.getSVGDocument();
> doc.getDocumentElement().appendChild( myMethod(Code) );
Yes there is. You can use the (de facto standard) parseXML function.
This is usually used from script, and unfortunately I can't see a way to
access the Window object to get at the parseXML method without
evaluating some script. So you could perhaps do the following. I
extend the JSVGCanvas here to get access to the script interpreter:
<untested-code>
import org.apache.batik.script.Interpreter;
// ...
public class MyJSVGCanvas extends JSVGCanvas {
/**
* Returns an Interpreter for the currently loaded document.
*/
public Interpreter getInterpreter(String type) {
return bridgeContext.getInterpreter(type);
}
}
// ...
String xml = "<polygon fill=\"none\" points=\"240.0, 243.0, ...\"
stroke=\"#000000\"/>";
Interpreter in = mycanvas.getInterpreter("text/ecmascript");
Node n = (Node) in.evaluate("parseXML('" + xml + "')");
SVGDocument doc = mycanvas.getSVGDocument();
doc.getDocumentElement().appendChild(n);
</untested-code>
Cameron
--
e-mail : cam (at) mcc.id.au icq : 26955922
web : http://mcc.id.au/ msn : cam-msn (at) aka.mcc.id.au
office : +61399055779 jabber : heycam (at) jabber.org
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]