Hi Fulio,

The code you posted has no chance of working in SVG because innerText
is not part of the SVG DOM - you need to first clear all the children
of the group, then create and append a new text element to it. Also,
your function is not called in the page, so has no chance of firing -
I would use the onload handler of the svg element to call it like this:

<svg width="100%" height="100%" version="1.1"
xmlns="http://www.w3.org/2000/svg"; onload="writeText(evt);">

You then need something like this to do what you want:

function writeText(evt)
{
    /* SVG namespace */
    var svgns = "http://www.w3.org/2000/svg";;
    /* get a reference to the SVG document element */
    var svgDoc = evt.target.ownerDocument;
    /* map element ids and chinese chars */
    var map = {'moon': 'hello &x6708;', 'tree': '&x6728;', 'man':
'&x4eba;', 'water': '&x6c34;'};
    for (el_id in map) {
        /* get the g element */
        var el = svgDoc.getElementById(el_id);
        /* clear the children of the g element */
        if (el.hasChildNodes()) {
            while (el.childNodes.length >= 1) {
                el.removeChild(el.firstChild);
            }
        }
        /* create a new text element */
        var textel = svgDoc.createElementNS(svgns, "text");
        /* create a text node for the text content */
        var text = svgDoc.createTextNode(map[el_id]);
        /* append the text node to the text element */
        textel.appendChild(text);
        /* append the text element to the g element */
        el.appendChild(textel);
    }
}

However, this doesn't work for a number of reasons - your HTML example
did not work in my browser - the unicode characters could not be
displayed - I guess I would have the same problem in SVG. Also, the
text element in the above example is not styled in any way, so takes
on the style of its parent g element - you could add styles using
textel.setAttributeNS(null, name, value).

I hope the above helps you get a little further with your problem.


--- In svg-developers@yahoogroups.com, Fulio Pen <[EMAIL PROTECTED]> wrote:
>
> hello, 
> 
> I am trying to replace the English object names in an svg file with
Chinese ideographic writing.  My purpose to compare the
> 
> features of English and Chinese writing.  Following is the svg file:
> 
> http://www.pinyinology.com/test/chinese2.svg
> 
> 
> And following is the code which is already in the svg file: 
> 
> 
> <script type="text/javascript">
> function chinText()
> {
>   document.getElementById("moon").innerHTML = "\u6708"; 
> document.getElementById("tree").innerHTML = "\u6728";
> document.getElementById("man").innerHTML = "\u4eba";
> document.getElementById("water").HTML =  "\u6c34";
> }
> </script>
> 
> I tested the above code in an
> html page. It works. But I don't know how to implement the code in
the svg file. Following is the html page:
> 
> http://www.pinyinology.com/test/span2.html 
> 
> I hope someone can help me. Thanks for your expertise. 
> 
> Fulio Pen
> 
> 
>       
> 
> [Non-text portions of this message have been removed]
>



------------------------------------

-----
To unsubscribe send a message to: [EMAIL PROTECTED]
-or-
visit http://groups.yahoo.com/group/svg-developers and click "edit my 
membership"
----Yahoo! Groups Links

<*> To visit your group on the web, go to:
    http://groups.yahoo.com/group/svg-developers/

<*> Your email settings:
    Individual Email | Traditional

<*> To change settings online go to:
    http://groups.yahoo.com/group/svg-developers/join
    (Yahoo! ID required)

<*> To change settings via email:
    mailto:[EMAIL PROTECTED] 
    mailto:[EMAIL PROTECTED]

<*> To unsubscribe from this group, send an email to:
    [EMAIL PROTECTED]

<*> Your use of Yahoo! Groups is subject to:
    http://docs.yahoo.com/info/terms/

Reply via email to