xmlgraphics-batik-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Martin Jacobson <jacobson.mar...@gmail.com>
Subject Re: unable to add property to JavaScript node object
Date Tue, 03 Nov 2009 08:25:23 GMT
Hi again!

I'm stubborn too, so I looked at the example you gave, and tweaked it
slightly, as below...

<?xml version="1.0"?>
<!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN"
 "http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd">

<svg version="1.1" xmlns="http://www.w3.org/2000/svg" onload="init()">
 <script type="text/javascript">
   init = function(){
     testnode = document.getElementById("testnode");
     alert(testnode.fill);
     alert(testnode.getAttribute("fill"));
     testnode.setAttribute("fill", "red");
   }
 </script>
 <rect id="testnode" fill="black" width="100" height="100" x="150" y="150"/>
</svg>

When run through both Squiggle and Firefox 3.5 I get the same
behaviour; there is no public fill property - you have to use
getAttribute(). So the first alert() gives "undefined", and the second
gives "black". Then, the rectangle turns red. It seems that the
properties of DOM nodes are private, and can only be accessed using
get/set methods.

Martin


2009/11/3  <x.zupftom@web.de>:
> Martin,
>
> thanks anyway for your effort, I appreciate that!  I hope I'll be able to start a project
using Batik for SVG display and interaction.  That's one reason why I'm interested in what's
going on here.
>
> Vielen Dank!
> Thomas
>
>
>> -----Ursprüngliche Nachricht-----
>> Von: "Martin Jacobson" <jacobson.martin@gmail.com>
>> Gesendet: 03.11.09 08:05:36
>> An: batik-users@xmlgraphics.apache.org
>> Betreff: Re: unable to add property to JavaScript node object
>
>
>> Thomas,
>>
>> You're quite right to be stubborn! Unfortunately, I can no longer be
>> of much help: I use Batik, but I use the Java binding to the DOM, and
>> know much less about how the DOM interacts with JavaScript. I hope
>> someone with more experience of Javascript can help you.
>>
>> mit freundlichen gruessen,
>> Martin
>>
>> 2009/11/3  <x.zupftom@web.de>:
>> >> -----Ursprüngliche Nachricht-----
>> >> Von: "Martin Jacobson" <jacobson.martin@gmail.com>
>> >
>> >> I see what you mean, but the problem is, the properties of a DOM node
>> >> object ARE the attributes of the XML node!
>> >
>> >
>> > Sorry, but I doubt that.  Take the following example:
>> >
>> > <?xml version="1.0"?>
>> > <!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN"
>> >  "http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd">
>> >
>> > <svg version="1.1" xmlns="http://www.w3.org/2000/svg" onload="init()">
>> >  <script type="text/javascript">
>> >    init = function(){
>> >      testnode = document.getElementById("testnode")
>> >      alert(testnode.fill)
>> >      alert(testnode.getAttributeNS(null,"fill"))
>> >      testnode.fill="red"
>> >    }
>> >  </script>
>> >  <rect id="testnode" fill="black" width="100" height="100" x="150" y="150"/>
>> > </svg>
>> >
>> >
>> > If you were right, then alert(testnode.fill) should say "black", but it doesn't.
 Neither with Batik nor in any Browser I tested.  Likewise, testnode.fill="red" should change
the rect's color to red, but it doesn't.  I get the familiar error message:
>> >
>> > Java class "org.apache.batik.dom.svg.SVGOMRectElement" has no public instance
field or method named "fill". (Inline <script> file://localhost/E:/programmieren/svg/js/js_attribute_to_node_object_4.svg:6#6)
>> >
>> >> Adding an arbitrary
>> >> Javascript property to a DOM node is the same thing as adding that
>> >> attribute to the XML node, so if that attribute isn't allowed by the
>> >> DTD, I guess Batik is - unfortunately for you! - correct to disallow
>> >> it.
>> >
>> > According to the DTD, the fill attribute is allowed, but Batik still doesn't
accept it.  On the other hand, Batik allows me to add an XML attribute to the rect node that,
according to the DTD, isn't allowed:
>> >
>> >
>> > <?xml version="1.0"?>
>> > <!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN"
>> >  "http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd">
>> >
>> > <svg version="1.1" xmlns="http://www.w3.org/2000/svg" onload="init()">
>> >  <script type="text/javascript">
>> >    init = function(){
>> >      testnode = document.getElementById("testnode")
>> >      testnode.setAttributeNS(null,"myAttribute","test")
>> >      alert(testnode.getAttributeNS(null,"myAttribute"))
>> >    }
>> >  </script>
>> >  <rect id="testnode" fill="black" width="100" height="100" x="150" y="150"/>
>> > </svg>
>> >
>> >
>> >> As a practical alternative, can't you define an object that *contains*
>> >> the DOM node, plus any other properties you may wish to add?
>> >>
>> >
>> > Certainly, I can work around this.  But I still would like to clarify whether
this is a bug in Batik or on purpose.  Sorry if I'm becoming stubborn, but I really want
to understand what's right and wrong in this context.
>> >
>> > Thomas W.
>> > ______________________________________________________
>> > GRATIS für alle WEB.DE-Nutzer: Die maxdome Movie-FLAT!
>> > Jetzt freischalten unter http://movieflat.web.de
>> >
>> >
>> > ---------------------------------------------------------------------
>> > To unsubscribe, e-mail: batik-users-unsubscribe@xmlgraphics.apache.org
>> > For additional commands, e-mail: batik-users-help@xmlgraphics.apache.org
>> >
>> >
>>
>>
>>
>> --
>> From my MacBook Pro
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: batik-users-unsubscribe@xmlgraphics.apache.org
>> For additional commands, e-mail: batik-users-help@xmlgraphics.apache.org
>>
>>
>
>
> ________________________________________________________________
> DSL-Preisknaller: DSL-Komplettpakete schon für 16,99 Euro/mtl.!*
> http://produkte.web.de/go/02/
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: batik-users-unsubscribe@xmlgraphics.apache.org
> For additional commands, e-mail: batik-users-help@xmlgraphics.apache.org
>
>



-- 
>From my MacBook Pro

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


Mime
View raw message