Hello,
You can do something like:
Document doc = ...; // Your SVG document.
Element svg = doc.getDocumentElement();
Element rect doc.createElementNS(svgNS, "rect");
svg.appendChild(rect);
rect.setAttribute(...);
Element script = doc.createElementNS(svgNS, "script");
Element scriptCode = doc.createTextElement("function showDialog() { \n
alert('msg'); })");
script.appendChild(scriptCode);
svg.appendChild(script);
Actually, it is better practice to put your code in a CDATA section
and use the createCDATASection method to do so.
I hope this helps,
Regards,
Vincent.
still wrote:
> Hi,all:
> I try to create a SVG DOM object via batik api.
> The SVG DOM should be look like this:
> //------------
> <?xml version="1.0" encoding="UTF-8"?>
> <svg xmlns="http://www.w3.org/2000/svg" width="400" height="450">
> <script type="text/ecmascript">
>
> function showDialog(msg) {
> alert(msg);
> }
> </script>
>
> <rect x="10" y="20" width="100" style="fill:red" height="50"
> onmousedown="showDialog('onmousedown')"/>
> </svg>
> //------------
> it is easy to create the "rect" element to the svg dom tree.but I can
> not
> figure out how to add the script functions and how to add the invoke
> statement in the element rect.
> It seems I should use the package org.apache.batik.script.rhino .
> Who could show me a simple sample about it?
> Thanks in advance
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: [EMAIL PROTECTED]
> For additional commands, e-mail: [EMAIL PROTECTED]
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]