XML Events

Last updated

In computer science and web development, XML Events is a W3C standard [1] for handling events that occur in an XML document. These events are typically caused by users interacting with the web page using a device, such as a web browser on a personal computer or mobile phone.

Contents

Formal definition

An XML Event is the representation of some asynchronous occurrence (such as a mouse button click) that gets associated with a 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

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

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

Legacy HTML and early SVG versions bind events to presentation elements 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 JavaScript’s onclick attribute):

Stay <a href="http://www.example.org" onclick="window.alert('Hello!'); return false;">here</a>!

This design has three drawbacks:

  1. it hard-wires the events into the language, so that adding new event types requires changes to the language
  2. it forces authors to mix the content of the document with the specifications of the scripting and event handling, rather than allowing them to separate them.
  3. it restricts authors to a single scripting language per document.

Relationship to other standards

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

Example of XML Events using a listener in XForms

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>Do it!</xf:label></xf:trigger><scriptxml:id="doit"type="application/ecmascript"> alert("test"); </script></html>

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 element) is executed.

See also

Related Research Articles

A document type definition (DTD) is a set of markup declarations that define a document type for an SGML-family markup language.

Document Object Model Convention for representing and interacting with objects in HTML, XHTML and XML documents

The Document Object Model (DOM) is a cross-platform and language-independent interface that treats an XML or HTML document as a tree structure wherein each node is an object representing a part of the document. The DOM represents a document with a logical tree. Each branch of the tree ends in a node, and each node contains objects. DOM methods allow programmatic access to the tree; with them one can change the structure, style or content of a document. Nodes can have event handlers attached to them. Once an event is triggered, the event handlers get executed.

HTML Hypertext Markup Language

Hypertext Markup Language (HTML) is the standard markup language for documents designed to be displayed in a web browser. It can be assisted by technologies such as Cascading Style Sheets (CSS) and scripting languages such as JavaScript.

Scalable Vector Graphics Open standard for two-dimensional vector graphics

Scalable Vector Graphics (SVG) is an Extensible Markup Language (XML)-based vector image format for two-dimensional graphics with support for interactivity and animation. The SVG specification is an open standard developed by the World Wide Web Consortium (W3C) since 1999.

Extensible Markup Language (XML) is a markup language that defines a set of rules for encoding documents in a format that is both human-readable and machine-readable. The World Wide Web Consortium's XML 1.0 Specification of 1998 and several other related specifications—all of them free open standards—define XML.

XFORM (Singular) is the Acronym for the word Transformation. As cited by Commonly used within the context of digital transformation or organizations.

XML Linking Language, or XLink, is an XML markup language and W3C specification that provides methods for creating internal and external links within XML documents, and associating metadata with those links.

XInclude is a generic mechanism for merging XML documents, by writing inclusion tags in the "main" document to automatically include other documents or parts thereof. The resulting document becomes a single composite XML Information Set. The XInclude mechanism can be used to incorporate content from either XML files or non-XML text files.

DOM events are actions that occurs as a result of the user action or as result of state change of the elements of a DOM tree. Client-side scripting languages like JavaScript, JScript, ECMAScript, VBScript, and Java can register various event handlers or listeners on the element nodes inside a DOM tree, such as in HTML, XHTML, XUL, and SVG documents.

A user interface markup language is a markup language that renders and describes graphical user interfaces and controls. Many of these markup languages are dialects of XML and are dependent upon a pre-existing scripting language engine, usually a JavaScript engine, for rendering of controls and extra scriptability.

XML namespaces are used for providing uniquely named elements and attributes in an XML document. They are defined in a W3C recommendation. An XML instance may contain element or attribute names from more than one XML vocabulary. If each vocabulary is given a namespace, the ambiguity between identically named elements or attributes can be resolved.

The following tables compare Document Object Model (DOM) compatibility and support for a number of JavaScript engines used in web browsers.

Cross-browser compatibility is the ability of a website or web application to function across different browsers and degrade gracefully when browser features are absent or lacking.

ItsNat Natural AJAX, is an open-source Java component-based Ajax framework.

eXtensible HyperText Markup Language (XHTML) is part of the family of XML markup languages. It mirrors or extends versions of the widely used HyperText Markup Language (HTML), the language in which Web pages are formulated.

SVG animation

Animation of Scalable Vector Graphics, an open XML-based standard vector graphics format, is possible through various means:

In computing, Facelets is an open-source Web template system under the Apache license and the default view handler technology for JavaServer Faces (JSF). The language requires valid input XML documents to work. Facelets supports all of the JSF UI components and focuses completely on building the JSF component tree, reflecting the view for a JSF application.

HTML attributes are special words used inside the opening tag to control the element's behaviour. HTML attributes are a modifier of an HTML element type. An attribute either modifies the default functionality of an element type or provides functionality to certain element types unable to function correctly without them. In HTML syntax, an attribute is added to an HTML start tag.

XHTML+RDFa is an extended version of the XHTML markup language for supporting RDF through a collection of attributes and processing rules in the form of well-formed XML documents. XHTML+RDFa is one of the techniques used to develop Semantic Web content by embedding rich semantic markup. Version 1.1 of the language is a superset of XHTML 1.1, integrating the attributes according to RDFa Core 1.1. In other words, it is an RDFa support through XHTML Modularization.

References

  1. "XML Events: An Events Syntax for XML". World Wide Web Consortium. 2003-10-14. Retrieved 2008-11-19.