You are viewing a plain text version of this content. The canonical link for it is here.
Posted to batik-users@xmlgraphics.apache.org by "Barbisch, Martin" <ba...@sony.de> on 2002/08/23 11:58:22 UTC

JavaScript String (.length) problem

Hello Batik users,

I have got a problem with the JavaScript part of Batik. Whenever I get an
attribute of an element or the content of a text node and try to determine
the length of that string I do not get a number but some
JavaScript-Code-String. Please see the code below.
Getting the length of a selfmade string works fine.

Thanks for your help,

Martin


[Batik 1.5beta3, JDK 1.4, Windows 2000]



<?xml version="1.0" encoding="iso-8859-1"?>

<svg width="300" height="200">

  <script type="text/ecmascript"> <![CDATA[

    function showId() {

        var textNode = document.getElementById("TestString");
        var str      = textNode.getAttribute("id");
        var strLen   = str.length;

        alert("string: " + str + "  length: " + strLen);
    }

  ]]> </script>


  <a onclick="showId()">
    <text id="TestString" x="70" y="100" font-size="40">Click me.</text>
  </a>

</svg>

---------------------------------------------------------------------
To unsubscribe, e-mail: batik-users-unsubscribe@xml.apache.org
For additional commands, e-mail: batik-users-help@xml.apache.org


Re: JavaScript String (.length) problem

Posted by Jim Ley <ji...@jibbering.com>.
"Christophe Jolif" <cj...@ilog.fr>

> In the meanwhile you
> will get the result you are expecting by using str.length() instead of
> string.length.

This would make you incompatible with other SVG script implementations,
if you specifically cast it to a ecmascript string, you'll be compatible
and get the desired result:

        var textNode = document.getElementById("TestString");
        var str      = String(textNode.getAttribute("id"));
        var strLen   = str.length;

(or just +'' which is often better than String( ... ) )

Jim.


---------------------------------------------------------------------
To unsubscribe, e-mail: batik-users-unsubscribe@xml.apache.org
For additional commands, e-mail: batik-users-help@xml.apache.org


Re: JavaScript String (.length) problem

Posted by Christophe Jolif <cj...@ilog.fr>.
Martin,

This is probably due to the fact that our ECMAScript DOM is a binding of the 
Java DOM and thus the string is the mapping of a Java String and not an 
ECMAScript string. I agree that it would be better to have an ECMAScript 
string and I encourage you to enter an RFE on Bugzilla. In the meanwhile you 
will get the result you are expecting by using str.length() instead of 
string.length.

Thanks.

Barbisch, Martin wrote:

> Hello Batik users,
> 
> I have got a problem with the JavaScript part of Batik. Whenever I get an
> attribute of an element or the content of a text node and try to determine
> the length of that string I do not get a number but some
> JavaScript-Code-String. Please see the code below.
> Getting the length of a selfmade string works fine.
> 
> Thanks for your help,
> 
> Martin
> 
> 
> [Batik 1.5beta3, JDK 1.4, Windows 2000]
> 
> 
> 
> <?xml version="1.0" encoding="iso-8859-1"?>
> 
> <svg width="300" height="200">
> 
>   <script type="text/ecmascript"> <![CDATA[
> 
>     function showId() {
> 
>         var textNode = document.getElementById("TestString");
>         var str      = textNode.getAttribute("id");
>         var strLen   = str.length;
> 
>         alert("string: " + str + "  length: " + strLen);
>     }
> 
>   ]]> </script>
> 
> 
>   <a onclick="showId()">
>     <text id="TestString" x="70" y="100" font-size="40">Click me.</text>
>   </a>
> 
> </svg>
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: batik-users-unsubscribe@xml.apache.org
> For additional commands, e-mail: batik-users-help@xml.apache.org
> 
> 
> 
> 


-- 
Christophe


---------------------------------------------------------------------
To unsubscribe, e-mail: batik-users-unsubscribe@xml.apache.org
For additional commands, e-mail: batik-users-help@xml.apache.org