This articleneeds additional citations forverification. Please helpimprove this article byadding citations to reliable sources. Unsourced material may be challenged and removed. Find sources: "XML Events" – news ·newspapers ·books ·scholar ·JSTOR(November 2008) (Learn how and when to remove this message) |
Incomputer science andweb development,XML Events is aW3C standard[1] for handlingevents that occur in anXML document. These events are typically caused by users interacting with the web page using a device, such as aweb browser on apersonal computer ormobile phone.
An XML Event is the representation of someasynchronous occurrence (such as amouse button click) that gets associated with a data element in anXML document. XML Events provides a static, syntactic binding to theDOM Events interface, allowing the event to be handled.
The XML Events standard is defined to provide XML-based languages with the ability to uniformly integrateevent listeners and associatedevent handlers withDocument Object Model (DOM) Level 2 event interfaces. The result is to provide a declarative, interoperable way of associating behaviors with XML-based documents such asXHTML.
XML Events uses aseparation of concernsdesign pattern, and is technology-neutral with regard tohandlers. It gives authors freedom in organizing their code and allows separation of document content fromscripting.
LegacyHTML and earlySVG versions bind events to presentation elements by encoding the event name in anattribute name, such that the value of the attribute is the action for that event at that element. For example, (withJavaScript’sonclick attribute):
Stay <a href="http://www.example.org">here</a>!
This design has three drawbacks:
UnlikeDOM Events, which are usually associated with HTML documents, XML events are designed to be independent of specific devices. XML Events are used extensively inXForms and in version 1.2 of theSVG specification, as of July 2006[update], which is still a working draft.
The following is an example of how XML events are used in the XForms specification:
<htmlxmlns="http://www.w3.org/1999/xhtml"xmlns:ev="http://www.w3.org/2001/xml-events"xmlns:xf="http://www.w3.org/2002/xforms"><head><ev:listenerevent="DOMActivate"observer="myButton"handler="#doit"/></head><xf:triggerxml:id="myButton"><xf:label>Doit!</xf:label></xf:trigger><scriptxml:id="doit"type="application/ecmascript">alert("test");</script></html>
In this example, when theDOMActivate event occurs on the data element with an id attribute ofmyButton, the handlerdoit (for example, a JavaScript element) is executed.