This appendix is normative.
This appendix provides an introduction to the SVG DOM and discusses the relationship of the SVG DOM with the Document Object Model (DOM) Level 2 Specification [DOM2]. The specific SVG DOM interfaces that correspond to particular sections of the SVG specification are defined at the end of corresponding chapter in this specification, as follows:
The SVG DOM is builds upon and is compatible with the Document Object Model (DOM) Level 2 Specification [DOM2]. In particular:
A DOM application can use the hasFeature method of the DOMImplementation interface to verify that the interfaces listed in this section are supported. The list of available interfaces is provided in section Feature strings for the hasFeature method call.
The SVG DOM follows similar naming conventions to the Document Object Model HTML [DOM2-HTML].
All names are defined as one or more English words concatenated together to form a single string. Property or method names start with the initial keyword in lowercase, and each subsequent word starts with a capital letter. For example, a property that returns document meta information such as the date the file was created might be named "fileDateCreated". In the ECMAScript binding, properties are exposed as properties of a given object. In Java, properties are exposed with get and set methods.
For attributes with the CDATA data type, the case of the return value is that given in the source document.
This exception is raised when a specific SVG operation is impossible to perform.
exception SVGException { unsigned short code; }; // SVGExceptionCode const unsigned short SVG_WRONG_TYPE_ERR = 0; const unsigned short SVG_INVALID_VALUE_ERR = 1; const unsigned short SVG_MATRIX_NOT_INVERTABLE = 2;
The feature strings that are available for the hasFeature method call that is part of the SVG DOM's support for the DOMImplementation interface defined in [DOM2-CORE] are the same features strings available for the requiredFeatures attribute that is available for many SVG elements.
The version number for the hasFeature method call is "1.0".
The SVG DOM supports the following interfaces and event types from [DOM2-EVENTS]:
Each SVG element which has at least one event attribute assigned to it in the SVG DTD supports the DOM2 event registration interfaces [DOM2-EVREG] and can be registered as an event listener for the corresponding DOM2 event using the event registration interfaces. Thus, for example, if the SVG DTD indicates that a given element supports the "onclick" event attribute, then an event listener for the "click" event can be registered with the given element as the event target.
SVG's animation elements also support the DOM2 event registration interfaces [DOM2-EVREG]. Event listeners for animation events (i.e., start, end or repeat) can be registered on any of the animation elements.
Event listeners which are established by DOM2 Event registration interfaces [DOM2-EVREG] receive events before any event listeners that correspond to event attributes (see Event attributes) or animations.
In Java, one way that event listeners can be established is to define a class which implements the EventListener interface, such as:
class MyAction1 implements EventListener { public void handleEvent(Event evt) { // process the event } } // ... later ... MyAction1 mc1 = new MyAction1(); myElement.addEventListener("DOMActivate", mc1, false);
In ECMAScript, one way to establish an event listener is to define a function and pass the name of that function to the addEventListener method:
function myAction1(evt) { // process the event } // ... later ... myElement.addEventListener("DOMActivate", myAction1, false)
In ECMAScript, the character data content of an Event attribute become the definition of the ECMAScript function which gets invoked in response to the event. As with all registered ECMAScript event listener functions, this function receives an Event object as a parameter, and the name of the Event object is evt. For example, it is possible to say:
<rect onactivate="MyActivateHandler(evt)" .../>
which will pass the Event object evt
into function MyActivateHandler
.
The section describes the facilities from the Document Object Model CSS [DOM2-CSS], the CSS OM, that are part of the SVG DOM.
User agents that do not support styling with CSS are only required to support the following interfaces from [DOM2-CSS], along with any interfaces necessary to implement the interfaces, such as CSSPrimitiveValue and CSSValueList. These interfaces are used in conjunction with the getPresentationAttribute method call on interface SVGStylable. This method must be supported on all implementations of the SVG DOM:
User agents that support Styling with CSS, the SVG DOM, and aural styling [CSS2-AURAL] must support all of the interfaces defined in [DOM2-CSS] which apply to aural properties.
For visual media [CSS2-VISUAL], the SVG DOM supports all of the required interfaces defined in [DOM2-CSS]. All of the interfaces that are optional for [DOM2-CSS] are also optional for the SVG DOM.
Whether or not a user agent supports styling with CSS, a user agent still must support interface CSSValue, as this is the type that is returned from the getPresentationAttribute method call on interface SVGStylable.
[DOM2-CSS] defines a set of extended interfaces [DOM2-CSS-EI] for use in conjunction with interface CSSValue. The table below specifies the type of CSSValue [DOM2-CSSVALUE] used to represent each SVG property that applies to visual media [CSS2-VISUAL]. The expectation is that the CSSValue returned from the getPropertyCSSValue method on the CSSStyleDeclaration interface or the getPresentationAttribute method on the SVGStylable interface can be cast down, using binding-specific casting methods, to the specific derived interface.
For properties that are represented by a custom interface (the valueType of the CSSValue is CSS_CUSTOM), the name of the derived interface is specified in the table. For these properties, the table below indicates which extended interfaces are mandatory and which are not.
For properties that consist of lists of values (the valueType of the CSSValue is CSS_VALUE_LIST), the derived interface is CSSValueList. For all other properties (the valueType of the CSSValue is CSS_PRIMITIVE_VALUE), the derived interface is CSSPrimitiveValue.
For shorthand properties, a CSSValue always will have a value of null. Shorthand property values can only be accessed and modified as strings.
The SVG DOM defines the following SVG-specific custom property interfaces, all of which are mandatory for SVG user agents:
If a script sets a DOM attribute to an invalid value (e.g., a negative number for an attribute that requires a non-negative number or an out-of-range value for an enumeration), unless this specification indicates otherwise, no exception shall be raised on setting, but the given document fragment shall become technically in error as described in Error processing.