xmlgraphics-batik-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From x.zupf...@web.de
Subject Re: unable to add property to JavaScript node object
Date Mon, 02 Nov 2009 20:12:38 GMT
Hi Martin,

I appreciate your effort, but alas that's not what I meant.  This is not about attributes
of an XML node but about JavaScript properties of a DOM node object.  In my understanding,
XML attributes, which are accessed and set using the set/getAttributeNS() methods, are totally
independent from the JavaScript properties, which are accessed and set using the dot notation
and usual JavaScript assignment.

I'm not a JavaScript expert.  I learned that JavaScript objects can be dynamically extended
and modified, and I am surprised Batik makes an exception for node objects.  Aren't node objects
just usual objects?  At least typeof returns the type "object".

Thomas W.



> -----Ursprüngliche Nachricht-----
> Von: "Martin Jacobson" <jacobson.martin@gmail.com>
> Gesendet: 02.11.09 17:52:32
> An: batik-users@xmlgraphics.apache.org
> Betreff: Re: unable to add property to JavaScript node object


> This works in Squiggle...
> 
> <?xml version="1.0" encoding="UTF-8"?>
> <!DOCTYPE svg PUBLIC '-//W3C//DTD SVG 1.0//EN'
>           'http://www.w3.org/TR/2001/REC-SVG-20010904/DTD/svg10.dtd'
> [
> <!ATTLIST rect
>   xmlns:my CDATA #FIXED "http://www.web.de/xzupftom"
>   my:Property CDATA #IMPLIED >
> ]>
> <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("http://www.web.de/xzupftom",
> "my:Property", "test");
>    }
>  </script>
>  <rect id="testnode" width="100" height="100" x="150" y="150"/>
> </svg>
> 
> Look at the DOM when this has loaded, and you'll see the my:Property
> attribute set to the value "test"
> 
> HTH
> Martin
> 
> 
> 2009/11/2 Martin Jacobson <jacobson.martin@gmail.com>:
> > Maybe the experts will come up with a better explanation, but this is
> > the expected behaviour: the SVG DTD doesn't define a myProperty
> > attribute for the rect element, so Batik (correctly) refuses to allow
> > you to set its value - however, you can declare new attributes for
> > most SVG elements (see the SVG specs for details). The fact that
> > Firefox et al don't barf, is probably that they don't validate the
> > SVG, merely test it for well-formedness.
> >
> > HTH
> > Martin
> >
> >
> > 2009/11/2  <x.zupftom@web.de>:
> >> Hi all,
> >>
> >> I asked the following question on the SVG-developers list, but I guess you guys
can help me better:  Why is it impossible to add a property to a DOM node with Batik?  I
have the following test SVG:
> >>
> >>
> >> <?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.myProperty = "test"
> >>      alert(testnode.myProperty)
> >>    }
> >>  </script>
> >>  <rect id="testnode" width="100" height="100" x="150" y="150"/>
> >> </svg>
> >>
> >>
> >> It works perfectly in Firefox, Opera, IE+ASV and Safari, but Squiggle (Batik
1.8pre+r801641) gives me the following Java error message:
> >>
> >> Java class "org.apache.batik.dom.svg.SVGOMRectElement" has no public instance
field or method named "myProperty". (Inline <script> file:/E:/programmieren/svg/js/js_attribute_to_node_object_4.svg:6#4)
> >>
> >> Of course I can't dynamically add a property to a Java object, but this is JavaScript,
so I guess I should be able to add my custom properties.  I initially thought this could
be Rhino's fault, but I threw the exact same script into an HTML document and tested it with
Lobo (AFAIK it uses Rhino as well).  This works as expected:
> >>
> >>
> >> <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
> >>       "http://www.w3.org/TR/html4/loose.dtd">
> >> <html>
> >>  <head>
> >>    <script type="text/javascript">
> >>      init = function(){
> >>        testnode = document.getElementById("testnode")
> >>        testnode.myProperty = "test"
> >>        alert(testnode.myProperty)
> >>      }
> >>    </script>
> >>  </head>
> >>  <body onload="init()">
> >>    <p id="testnode">testnode</p>
> >>  </body>
> >> </html>
> >>
> >>
> >> Why aren't the Java DOM node objects properly wrapped as JavaScript objects?
 Is this by purpose or just a missing feature?
> >>
> >> By the way, java -version on Windows XP gives me the following:
> >> java version "1.6.0_13"
> >> Java(TM) SE Runtime Environment (build 1.6.0_13-b03)
> >> Java HotSpot(TM) Client VM (build 11.3-b02, mixed mode)
> >>
> >> Any info is greatly appreciated
> >> Thomas Weber
> >> ________________________________________________________________
> >> 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
> >
> 
> 
> 
> -- 
> 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
> 
> 


______________________________________________________
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


Mime
View raw message