XML Events is a W3C specification for handling events occurring in an XML document. These events are typically caused by a user interacting with the document as a web page using a device such as a web browser on a PC, mobile phone or telephone.

Formal Definition Edit

Technically an XML event is the representation of some asynchronous occurrence (such as a mouse click on a button) that gets associated with any data element in an XML document. XML Events provides a static, syntactic binding to the DOM Events interface, allowing the event to be handled.

Motivation Edit

The XML Events standard is defined to provide XML-based languages with the ability to uniformly integrate event listeners and associated event handlers with Document Object Model (DOM) Level 2 event interfaces. The result is to provide a declarative, interoperable way of associating behaviors with XML-based documents such as XHTML.

Advantages of XML Events Edit

XML Events uses a separation of concerns design pattern, and is technology neutral with regards to handlers. It gives authors freedom in organising their code, and allows separation of document content from scripting.

Both legacy HTML and early SVG versions bind events to a presentation element by encoding the event name in an attribute name, such that the value of the attribute is the action for that event at that element. For example (with the onclick attribute):

<p>Stay <a href="" onclick="window.alert('Hello!'); return false;">here</a>!</p>

This design has three drawbacks:

  1. it hard-wires the events into the language, so that to add a new event type, you have to make a change to the language
  2. it forces software developers to mix the content of the document with the specifications of the scripting and event handling, rather than allowing you to separate them out
  3. it restricts you to a single scripting language per document.

Relationship to Other StandardsEdit

Unlike DOM Events which are usually associated with HTML documents, XML events are designed to be independent of devices. XML Events are also used extensively in XForms, and in version 1.2 of the SVG specification, as of July 2006 still a working draft.

Example of XML Events using Listener in XFormsEdit

The following is an example of how XML events are used in the XForms specification:

      <ev:listener event="DOMActivate" observer="myButton" 

In this example, when the DOMActivate event occurs on the data element with an id attribute of myButton, the handler doit (for example a javascript script element) is executed.

See alsoEdit

External linksEdit

Template:W3C Standards Template:Web-stubde:XML Events

Community content is available under CC-BY-SA unless otherwise noted.