Thank you.It really works,and yes it is better to put the script in the
cdata section.
But the  problem is how to add a event(eg.a mousedown event) to the
element I create to invoke the script function I defined as following? 

<rect x="10" y="20" width="100" style="fill:red" height="50"
 onmousedown="showDialog('onmousedown')"/>
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^And is it the normal way to do so
^_^? I thought there will be  methods like:

doc.insertFunction(Function f) ; 
node.insertEvent(...);



-----Original Message-----
From: Vincent Hardy [mailto:[EMAIL PROTECTED]] 
Sent: 2002��7��19�� 16:00
To: Batik Users
Subject: Re: add script functions and event via batik api--how

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]



---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to