public Event createEvent(String eventType);
The string passed in is the type of event; valid values in DOM Level
2 are "UIEvent", "MutationEvent", and
"MouseEvent". Each of these has a corresponding class:
UIEvent, MutationEvent, and
MouseEvent. You'll note, in looking at the
Xerces Javadoc, that they provide only the
MutationEvent interface, which is the only event
type Xerces supports. When an event is "fired" off, it
can be handled (or "caught") by an
EventListener.
This is where the DOM core support comes in; a parser supporting DOM
events should have the org.w3c.dom.Node interface
implementing the org.w3c.dom.events.EventTarget
interface. So every node can be the target of an event. This means
that you have the following method available on those nodes:
public void addEventListener(String type, EventListener listener,
boolean capture);
Here's the process. You create a new
EventListener (which is a custom class you would
write) implementation. You need to implement only a single method:
public void handleEvent(Event event);
Register that listener on any and all nodes you want to work with.
Code in here typically does some useful task, like emailing users
that their information has been changed (in some XML file),
revalidating the XML (think XML editors), or asking users if they are
sure they want to perform the action.
At the same time, you'll want your code to trigger a new
Event on certain actions, like the user clicking
on a node in an IDE and entering new text, or deleting a selected
element. When the Event is triggered, it is passed
to the available EventListener instances, starting
with the active node and moving up. This is where your
listener's code executes, if the event types are the
same. Additionally, you can have the event stop
propagating at that point (once you've handled it), or bubble
up the event chain and possibly be handled by other registered
listeners.