Hi Andrew,

Andrew Rowlands <and...@madcore.com.au> wrote on 06/27/2010 09:07:50 PM:

> I'm new to Batik (and Java for that matter).  I'm trying to make a 
> flexible applet that I can change various properties of a loaded SVG via 

> javascript functions (not ECMAscript functions in the SVG file itself 
> but JS functions in the HTML file that the java applet is embedded in).
> 
> How it currently works:
> 
> In my java applet (using JSVGCanvas) there is a function 
> updateElement(), which basically does:
> Element elem = doc.getElementById(element_id)
> elem.setAttributeNS(null, attribute, value).
> 
> This is called in javascript/HTML land by:
> 
> myObject = document.getElementById(id_of_applet);
> myObject.updateElement("svg_element_id_to_update", "fill", "yellow");
> 

> It works great for the properties I can easily reference (e.g. fill, 
> stroke, opacity) etc. but I'm struggling trying to dynamically change 
> things like text content, xlink:href for textPath to change to a 
> different path and/or updating a path definition.

    Basically you need to take a course in DOM level 2.  The xlink:href
case is pretty similar to fill/stroke, except that the first argument to
'setAttributeNS' needs to be the xlink namespace (NS stands for 
namespace).

    Text content is a bit tricker as that is stored as DOM TextNodes 
that are children of the various elements.  So you need to remove the
previous children and create and append your new text nodes.

        I'm a little unsure what 'path definition' means as that is 
typically
stored in normal attributes (i.e. 'd' attribute etc).

> Can anyone shed any light on the java required to change the contents of 

> the text field, the textPath xlink:href and path definitions?

        I hope the above helps point you in the right direction.        

Reply via email to