The Xerces-J implementation of DOM Events is immature.

> Cast my Document to a DocumentImpl and query for the property
> "MutationEvents"
> 
>       DocumentImpl documentImpl = (DocumentImpl) document;
>       System.out.println("Mutation events = " +
> documentImpl.getMutationEvents());
>       documentImpl.setMutationEvents(true);
>       System.out.println("Mutation events = " +
> documentImpl.getMutationEvents());
> 
> This initially returns 'false', but returns 'true' after I update the
> property.

You shouldn't be required to do this, adding any event listener should be 
sufficient to enable mutation events (don't know if that is true or not).

> 
> I then created a MutationEvent to find out what the event 
> type might be.
> 
>       Event event = documentImpl.createEvent("MutationEvent");
>       System.out.println("Mutation event type = " + event.getType());
> 
> I initially used the type "MutationEvents", but that throws a 
> DOMException :
> NOT_SUPPORTED_ERR, so I used "MutationEvent" and that seemed 
> to work. This
> returns 'null'.

I reported that as bug 1814: 
http://nagoya.apache.org/bugzilla/show_bug.cgi?id=1814  My reading of the spec 
is that it should be "MutationEvents"

> 
> Now I add my event listener to the document.
> 
>       EventTarget eventTarget = (EventTarget) docSource.toDocument();
>       EventListener eventListener = new MyEventListener();
>       eventTarget.addEventListener("MutationEvent", 
> eventListener, false);
>       eventTarget.addEventListener("MutationEvent", 
> eventListener, true);
>       eventTarget.addEventListener(null, eventListener, false);
>       eventTarget.addEventListener(null, eventListener, true);
> 

The type argument to addEventListener should be the value of
Event.getType() that you want to catch.  For example,

eventTarget.addEventListener("DOMAttrModified",eventListener, false);


> Does anyone have an example of how to catch DOM mutation 
> events? Is there a
> way to do it using only the JAXP and DOM interfaces?

I have a series of DOM Events tests that I have been working 
on that you can download from the xmlconf CVS.

http://cvs.sourceforge.net/cgi-bin/viewcvs.cgi/xmlconf/domunit/JUNIT/NET/sourceforge/XMLCONF/DOMUNIT/dom2/events/

These all depend on being able to create events using 
documentEvent.createEvent("Events") or 
documentEvent.createEvent("MutationEvents"), so you have to either munge the 
tests or
fix the bug 1814 to even get started.



---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to