[Home] [By Thread] [By Date] [Recent Entries]

  • To: =?UTF-8?Q?"=E5=90=B4=E6=B9=96"?= <wuhu@i...>
  • Subject: Re: How can i use dom event to detect any modification to certain xml docs?
  • From: Chris Burdess <dog@b...>
  • Date: Wed, 14 Dec 2005 14:39:45 +0000
  • Cc: "'xml-dev@l...' " <xml-dev@l...>
  • In-reply-to: <E1EmXX8-00074p-00@d...>
  • References: <E1EmXX8-00074p-00@d...>

吴湖 wrote:
> I 'v read a lot of w3c specs about dom event.
> But still I don't know how to create or invoke dom events in java.
> java 1.5 does have the org.w3c.dom.events package which contains lots 
> of dom event interfaces, but how to implement them seems to be a 
> question that we programmers should answer. Am I right? or there 'r 
> already any implementation of these interfaces in java?
> Any help would mean a lot to me!

You create an event by casting the Document to a DocumentEvent and 
calling createEvent.

You dispatch an event to a node in the tree by casting it to an 
EventTarget and calling dispatchEvent on it.

You receive events by registering yourself as an EventListener on an 
EventTarget (addEventListener), whereupon you will receive events 
dispatched to that target (and possibly its descendents).

You can determine whether the implementation supports events by getting 
the DOMImplementation (Document.getImplementation) and calling 
hasFeature("events", "2.0") (or "uievents", "mutationevents", 
"htmlevents").

GNU Classpath, used in gcj, jamvm, sablevm, kaffe, cacao, and most 
other free JVMs, supports DOM events. I can't speak for other 
implementations.
-- 
Chris Burdess


Site Map | Privacy Policy | Terms of Use | Trademarks
Free Stylus Studio XML Training:
W3C Member