SVG contains a 'switch' element along with attributes 'requiredFeatures', 'requiredExtensions' and 'systemLanguage' to provide an ability to specify alternate viewing depending on the capabilities of a given user agent or the user's language.
<!ENTITY % SVG.Conditional.extra.attrib "" > <!ENTITY % SVG.Conditional.attrib "requiredFeatures %FeatureList.datatype; #IMPLIED requiredExtensions %ExtensionList.datatype; #IMPLIED systemLanguage %LanguageCodes.datatype; #IMPLIED %SVG.Conditional.extra.attrib;" > |
Attributes requiredFeatures, requiredExtensions and systemLanguage Attributes 'requiredFeatures', 'requiredExtensions' and 'systemLanguage' act as tests and return either true or false results. The 'switch' renders the first of its children for which all of these attributes test true. If the given attribute is not specified, then a true value is assumed.
Similar to the 'display' property, conditional processing attributes only affect the direct rendering of elements and do not prevent elements from being successfully referenced by other elements (such as via a 'use').
In consequence:
The 'switch' element evaluates the 'requiredFeatures', 'requiredExtensions' and 'systemLanguage' attributes on its direct child elements in order, and then processes and renders the first child for which these attributes evaluate to true. All others will be bypassed and therefore not rendered. If the child element is a container element such as a 'g', then the entire subtree is either processed/rendered or bypassed/not rendered.
Note that the values of properties 'display' and 'visibility' have no effect on 'switch' element processing. In particular, setting 'display' to none on a child of a 'switch' element has no effect on true/false testing associated with 'switch' element processing.
<!ENTITY % SVG.switch.extra.content "" > <!ENTITY % SVG.switch.element "INCLUDE" > <![%SVG.switch.element;[ <!ENTITY % SVG.switch.content "(( %SVG.Description.class; )*, ( %SVG.svg.qname; | %SVG.g.qname; | %SVG.use.qname; | %SVG.text.qname; | %SVG.Animation.class; %SVG.Conditional.class; %SVG.Image.class; %SVG.Shape.class; %SVG.Hyperlink.class; %SVG.Extensibility.class; %SVG.switch.extra.content; )*)" > <!ELEMENT %SVG.switch.qname; %SVG.switch.content; > <!-- end of SVG.switch.element -->]]> <!ENTITY % SVG.switch.attlist "INCLUDE" > <![%SVG.switch.attlist;[ <!ATTLIST %SVG.switch.qname; %SVG.Core.attrib; %SVG.Conditional.attrib; %SVG.Style.attrib; %SVG.Presentation.attrib; %SVG.GraphicalEvents.attrib; %SVG.External.attrib; transform %TransformList.datatype; #IMPLIED > |
For more information and an example, see Embedding foreign object types.
Definition of requiredFeatures:
If the attribute is not present, then its implicit return value is "true". If a null string or empty string value is given to attribute 'requiredFeatures', the attribute returns "false".
'requiredFeatures' is often used in conjunction with the 'switch' element. If the 'requiredFeatures' is used in other situations, then it represents a simple switch on the given element whether to render the element or not.
The 'requiredExtensions' attribute defines a list of required language extensions. Language extensions are capabilities within a user agent that go beyond the feature set defined in this specification. Each extension is identified by a URI reference.
Definition of requiredExtensions:
If a given URI reference contains white space within itself, that white space must be escaped.
If the attribute is not present, then its implicit return value is "true". If a null string or empty string value is given to attribute 'requiredExtensions', the attribute returns "false".
'requiredExtensions' is often used in conjunction with the 'switch' element. If the 'requiredExtensions' is used in other situations, then it represents a simple switch on the given element whether to render the element or not.
The URI names for the extension should include versioning information, such as "http://example.org/SVGExtensionXYZ/1.0", so that script writers can distinguish between different versions of a given extension.
The attribute value is a comma-separated list of language names as defined in Tags for the Identification of Languages [RFC3066].
Evaluates to "true" if one of the languages indicated by user preferences exactly equals one of the languages given in the value of this parameter, or if one of the languages indicated by user preferences exactly equals a prefix of one of the languages given in the value of this parameter such that the first tag character following the prefix is "-".
Evaluates to "false" otherwise.
Note: This use of a prefix matching rule does not imply that language tags are assigned to languages in such a way that it is always true that if a user understands a language with a certain tag, then this user will also understand all languages with tags for which this tag is a prefix.
The prefix rule simply allows the use of prefix tags if this is the case.
Implementation note: When making the choice of linguistic preference available to the user, implementers should take into account the fact that users are not familiar with the details of language matching as described above, and should provide appropriate guidance. As an example, users may assume that on selecting "en-gb", they will be served any kind of English document if British English is not available. The user interface for setting user preferences should guide the user to add "en" to get the best matching behavior.
Multiple languages MAY be listed for content that is intended for multiple audiences. For example, content that is presented simultaneously in the original Maori and English versions, would call for:
<text systemLanguage="mi, en"><!-- content goes here --></text>
However, just because multiple languages are present within the object on which the 'systemLanguage' test attribute is placed, this does not mean that it is intended for multiple linguistic audiences. An example would be a beginner's language primer, such as "A First Lesson in Latin," which is clearly intended to be used by an English-literate audience. In this case, the 'systemLanguage' test attribute should only include "en".
Authoring note: Authors should realize that if several alternative language objects are enclosed in a 'switch', and none of them matches, this may lead to situations where no content is displayed. It is thus recommended to include a "catch-all" choice at the end of such a 'switch' which is acceptable in all cases.
For the 'systemLanguage' attribute: Animatable: no.
If the attribute is not present, then its implicit return value is "true". If a null string or empty string value is given to attribute 'systemLanguage', the attribute returns "false".
'systemLanguage' is often used in conjunction with the 'switch' element. If the 'systemLanguage' is used in other situations, then it represents a simple switch on the given element whether to render the element or not.
The following list describes the applicability of the test attributes to the elements that do not directly produce rendering.
Documents often reference and use the contents of other files (and other Web resources) as part of their rendering. In some cases, authors want to specify that particular resources are required for a document to be considered correct.
Attribute 'externalResourcesRequired' is available on all container elements and to all elements which potentially can reference external resources. It specifies whether referenced resources that are not part of the current document are required for proper rendering of the given container element or graphics element.
Attribute definition:
This attribute applies to all types of resource references, including style sheets, color profiles (see Color profile descriptions) and fonts specified by a URI reference using a 'font-face' element or a CSS @font-face specification. In particular, if an element sets externalResourcesRequired="true", then all style sheets must be available since any style sheet might affect the rendering of that element.
Attribute 'externalResourcesRequired' is not inheritable (from a sense of attribute value inheritance), but if set on a container element, its value will apply to all elements within the container.
Because setting externalResourcesRequired="true" on a container element can have the effect of disabling progressive display of the contents of that container, tools that generate SVG content are cautioned against using simply setting externalResourcesRequired="true" on the outermost 'svg' element on a universal basis. Instead, it is better to specify externalResourcesRequired="true" on those particular graphics elements or container elements which specify need the availability of external resources in order to render properly.
For 'externalResourcesRequired': Animatable: no.
The 'id' and 'xml:base' attributes are available on all SVG elements:
Attribute definitions:
<!ENTITY % SVG.id.attrib "id ID #IMPLIED" > <!ENTITY % SVG.base.attrib "xml:base %URI.datatype; #IMPLIED" > <!ENTITY % SVG.lang.attrib "xml:lang %LanguageCode.datatype; #IMPLIED" > <!ENTITY % SVG.space.attrib "xml:space ( default | preserve ) #IMPLIED" > <!ENTITY % SVG.Core.extra.attrib "" > <!ENTITY % SVG.Core.attrib "%SVG.id.attrib; %SVG.base.attrib; %SVG.lang.attrib; %SVG.space.attrib; %SVG.Core.extra.attrib;" > |
Attribute definitions:
The Core Attribute Module defines the attribute set Core.attrib that is the core set of attributes that can be present on any element.
| Collection Name | Attributes in Collection |
|---|---|
| Core.attrib | id, xml:base, xml:lang, xml:space |
| Elements | Attributes | Content Model |
|---|---|---|
| svg | Core.attrib, Conditional.attrib, Style.attrib, x, y, width, height, viewBox, preserveAspectRatio, zoomAndPan, version, baseProfile, contentScriptType, contentStyleType, External.attrib, Presentation.attrib, GraphicalEvents.attrib, DocumentEvents.attrib | (Description.class | Structure.class | Shape.class | Image.class | View.class | Conditional.class | Hyperlink.class | Text.class | Script.class | Style.class | Marker.class | Clip.class | Mask.class | Gradient.class | Pattern.class | Filter.class | Cursor.class | Font.class | Animation.class | ColorProfile.class)* |
| g | Core.attrib, Conditional.attrib, Style.attrib, External.attrib, Presentation.attrib, GraphicalEvents.attrib, transform | (Description.class | Structure.class | Shape.class | Image.class | View.class | Conditional.class | Hyperlink.class | Text.class | Script.class | Style.class | Marker.class | Clip.class | Mask.class | Gradient.class | Pattern.class | Filter.class | Cursor.class | Font.class | Animation.class | ColorProfile.class)* |
| defs | Core.attrib, Conditional.attrib, Style.attrib, External.attrib, Presentation.attrib, GraphicalEvents.attrib, transform | (Description.class | Structure.class | Shape.class | Image.class | View.class | Conditional.class | Hyperlink.class | Text.class | Script.class | Style.class | Marker.class | Clip.class | Mask.class | Gradient.class | Pattern.class | Filter.class | Cursor.class | Font.class | Animation.class | ColorProfile.class)* |
| desc | Core.attrib, Style.attrib | (PCDATA)* |
| title | Core.attrib, Style.attrib | (PCDATA)* |
| metadata | Core.attrib | (PCDATA)* |
| symbol | Core.attrib, Style.attrib, External.attrib, viewBox, preserveAspectRatio, Presentation.attrib, GraphicsElementEventAttrs | (Description.class | Structure.class | Shape.class | Image.class | View.class | Conditional.class | Hyperlink.class | Text.class | Script.class | Style.class | Marker.class | Clip.class | Mask.class | Gradient.class | Pattern.class | Filter.class | Cursor.class | Font.class | Animation.class | ColorProfile.class)* |
| use | Core.attrib, Style.attrib, Conditional.attrib, transform, x, y, width, height, XLinkEmbed.attrib, Presentation.attrib, GraphicsElementEventAttrs | (Description.class | Animation.class)* |
The Structure Module defines the Description.class, Structure.class and Use.class content sets.
| Content Set Name | Elements in Content Set |
|---|---|
| Description.class | desc, title, metadata |
| Use.class | use |
| Structure.class | svg, g, defs, symbol, Use.class |
| Elements | Attributes | Content Model |
|---|---|---|
| svg | Core.attrib, Conditional.attrib, Style.attrib, x, y, width, height, viewBox, preserveAspectRatio, zoomAndPan, version, baseProfile, External.attrib, Presentation.attrib, GraphicalEvents.attrib, DocumentEvents.attrib | (Description.class | Structure.class | Shape.class | Image.class | View.class | Conditional.class | Hyperlink.class | Text.class | Script.class | Style.class | Marker.class | Clip.class | Mask.class | Gradient.class | Pattern.class | Filter.class | Cursor.class | Font.class | Animation.class | ColorProfile.class)* |
| g | Core.attrib, Conditional.attrib, Style.attrib, External.attrib, Presentation.attrib, GraphicalEvents.attrib, transform | (Description.class | Structure.class | Shape.class | Image.class | View.class | Conditional.class | Hyperlink.class | Text.class | Script.class | Style.class | Marker.class | Clip.class | Mask.class | Gradient.class | Pattern.class | Filter.class | Cursor.class | Font.class | Animation.class | ColorProfile.class)* |
| defs | Core.attrib, Conditional.attrib, Style.attrib, External.attrib, Presentation.attrib, GraphicalEvents.attrib, transform | (Description.class | Structure.class | Shape.class | Image.class | View.class | Conditional.class | Hyperlink.class | Text.class | Script.class | Style.class | Marker.class | Clip.class | Mask.class | Gradient.class | Pattern.class | Filter.class | Cursor.class | Font.class | Animation.class | ColorProfile.class)* |
| desc | Core.attrib, Style.attrib | (PCDATA)* |
| title | Core.attrib, Style.attrib | (PCDATA)* |
| metadata | Core.attrib | (PCDATA)* |
| use | Core.attrib, Style.attrib, Conditional.attrib, transform, x, y, width, height, XLinkEmbed.attrib, Presentation.attrib, GraphicsElementEventAttrs | (Description.class | Animation.class)* |
The Basic Structure Module defines the Description.class, Structure.class and Use.class content sets.
| Content Set Name | Elements in Content Set |
|---|---|
| Description.class | desc, title, metadata |
| Use.class | use |
| Structure.class | svg, g, defs, Use.class |
The Container Attribute Module defines the Container.attrib attribute set.
| Collection Name | Attributes in Collection |
|---|---|
| Container.attrib | enable-background |
| Elements | Attributes | Content Model |
|---|---|---|
| switch | Core.attrib, Conditional.attrib, External.attrib, Style.attrib, transform, Presentation.attrib, GraphicalEvents.attrib | (Description.class | Shape.class | Text.class | Structure.class | Image.class | Hyperlink.class | Extensibility.class | Animation.class)* |
The Conditional Processing Module defines the Conditional.class content set.
| Content Set Name | Elements in Content Set |
|---|---|
| Conditional.class | switch |
The Conditional Processing Module defines the Conditional.attrib attribute set.
| Collection Name | Attributes in Collection |
|---|---|
| Conditional.attrib | requiredFeatures, requiredExtensions, systemLanguage |
| Elements | Attributes | Content Model |
|---|---|---|
| image | Core.attrib, XLinkEmbed.attrib, Conditional.attrib, Style.attrib, External.attrib, GraphicalEvents.attrib, preserveAspectRatio, Paint.attrib, Opacity.attrib, Graphics.attrib, Cursor.attrib, Filter.attrib, Mask.attrib, GraphicalEvents.attrib, Clip.attrib, Profile.attrib, Viewport.attrib, transform, x, y, width, height | (Description.class | Animation.class)* |
The Image Module defines the Image.class content set.
| Content Set Name | Elements in Content Set |
|---|---|
| Image.class | image |
The following interfaces are defined below: SVGDocument, SVGSVGElement, SVGGElement, SVGDefsElement, SVGDescElement, SVGTitleElement, SVGSymbolElement, SVGUseElement, SVGElementInstance, SVGElementInstanceList, SVGImageElement, SVGSwitchElement, GetSVGDocument.
When an 'svg' element is embedded inline as a component of a document from another namespace, such as when an 'svg' element is embedded inline within an XHTML document [XHTML], then an SVGDocument object will not exist; instead, the root object in the document object hierarchy will be a Document object of a different type, such as an HTMLDocument object.
However, an SVGDocument object will indeed exist when the root element of the XML document hierarchy is an 'svg' element, such as when viewing a stand-alone SVG file (i.e., a file with MIME type "image/svg+xml"). In this case, the SVGDocument object will be the root object of the document object model hierarchy.
In the case where an SVG document is embedded by reference, such as when an XHTML document has an 'object' element whose 'href' attribute references an SVG document (i.e., a document whose MIME type is "image/svg+xml" and whose root element is thus an 'svg' element), there will exist two distinct DOM hierarchies. The first DOM hierarchy will be for the referencing document (e.g., an XHTML document). The second DOM hierarchy will be for the referenced SVG document. In this second DOM hierarchy, the root object of the document object model hierarchy is an SVGDocument object.
The SVGDocument interface contains a similar list of attributes and methods to the HTMLDocument interface described in the Document Object Model (HTML) Level 1 chapter of the [DOM1] specification.
IDL Definitioninterface SVGDocument : Document,Document,
events::
DocumentEvent {
readonly attribute DOMString
title; readonly attribute DOMString
referrer; readonly attribute DOMString
domain; readonly attribute DOMString
URL; readonly attribute SVGSVGElement rootElement; };
A key interface definition is the SVGSVGElement interface, which is the interface that corresponds to the 'svg' element. This interface contains various miscellaneous commonly-used utility methods, such as matrix operations and the ability to control the time of redraw on visual rendering devices.
SVGSVGElement extends ViewCSS and DocumentCSS to provide access to the computed values of properties and the override style sheet as described in DOM2.
IDL DefinitionDOM Level 2 Style [DOM2STYLE].
interface SVGSVGElement : SVGElement,SVGElement,
SVGTests,SVGTests,
SVGLangSpace,SVGExternalResourcesRequired,
SVGExternalResourcesRequired,SVGStylable,
SVGLocatable
SVGStylable,SVGFitToViewBox,
SVGLocatable,SVGZoomAndPan,
events::EventTarget
SVGFitToViewBox,events::DocumentEvent,
SVGZoomAndPan,css::ViewCSS,
css::DocumentCSS
{
EventTarget,readonly
attribute
SVGAnimatedLength
x;
readonly
attribute
SVGAnimatedLength
y;
readonly
attribute
SVGAnimatedLength
width;
readonly
attribute
SVGAnimatedLength
height;
DocumentEvent,attribute
DOMString
contentScriptType;
ViewCSS,//
raises
DOMException
on
setting
DocumentCSS {attribute
DOMString
readonly attribute SVGAnimatedLength x; readonly attribute SVGAnimatedLengthcontentStyleType
y; readonly attribute SVGAnimatedLength width; readonly attribute SVGAnimatedLength height;//
attributeraises
DOMString contentScriptType setraises(DOMException);on
setting
readonly
attribute
SVGRect
attribute DOMString contentStyleType setraises(DOMException); readonly attribute SVGRect viewport; readonly attribute float pixelUnitToMillimeterX; readonly attribute float pixelUnitToMillimeterY; readonly attribute float screenPixelToMillimeterX; readonly attribute float screenPixelToMillimeterY; attribute boolean useCurrentView; // raises DOMException on setting
setraises(DOMException); readonly attribute SVGViewSpec currentView; attribute float currentScale; // raises DOMException on setting
setraises(DOMException); readonly attribute SVGPoint currentTranslate; unsigned long suspendRedraw
(
in unsigned long max_wait_milliseconds
);
void
unsuspendRedraw
(
in unsigned long suspend_handle_id
)
raises(
DOMException
);
void
unsuspendRedrawAll
(
);
void
forceRedraw
(
);
void
pauseAnimations
(
);
void
unpauseAnimations
(
);
boolean
animationsPaused
(
);
float
getCurrentTime
(
);
void
setCurrentTime
(
in float seconds
);
NodeList
getIntersectionList
(
in SVGRect rect, in SVGElement referenceElement
);
NodeList
getEnclosureList
(
in SVGRect rect, in SVGElement referenceElement
);
boolean
checkIntersection
(
in SVGElement element, in SVGRect rect
);
boolean
checkEnclosure
(
in SVGElement element, in SVGRect rect
);
void
deselectAll
(
); SVGNumber
createSVGNumber
(
); SVGLength
createSVGLength
(
); SVGAngle
createSVGAngle
(
); SVGPoint
createSVGPoint
(
); SVGMatrix
createSVGMatrix
(
); SVGRect
createSVGRect
(
); SVGTransform
createSVGTransform
(
); SVGTransform
createSVGTransformFromMatrix
(
in SVGMatrix matrix
); Element
getElementById
(
in DOMString elementId
);
};
The position and size of the viewport (implicit or explicit) that corresponds to this 'svg' element. When the user agent is actually rendering the content, then the position and size values represent the actual values when rendering. The position and size values are unitless values in the coordinate system of the parent element. If no parent element exists (i.e., 'svg' element represents the root of the document tree), if this SVG document is embedded as part of another document (e.g., via the HTML 'object' element), then the position and size are unitless values in the coordinate system of the parent document. (If the parent uses CSS or XSL layout, then unitless values represent pixel units for the current CSS or XSL viewport, as described in the
CSS 2 specification.) If the parent element does not have a coordinate system, then the user agent should provide reasonable default values for this attribute.
The object itself and its contents are both readonly.
The definition of the initial view (i.e., before magnification and panning) of the current innermost SVG document fragment. The meaning depends on the situation:
The object itself and its contents are both readonly.
interface SVGGElement : SVGElement,SVGElement,
SVGTests,SVGTests,
SVGLangSpace, SVGExternalResourcesRequired, SVGStylable, SVGTransformable,events::
EventTarget { };
interface SVGDefsElement : SVGElement,SVGElement,
SVGTests,SVGTests,
SVGLangSpace, SVGExternalResourcesRequired, SVGStylable, SVGTransformable,events::
EventTarget { };
interface SVGDescElement : SVGElement,SVGElement,
SVGLangSpace,SVGLangSpace,
SVGStylable { };
interface SVGTitleElement : SVGElement,SVGElement,
SVGLangSpace,SVGLangSpace,
SVGStylable { };
interface SVGSymbolElement : SVGElement,SVGElement,
SVGLangSpace,SVGLangSpace,
SVGExternalResourcesRequired, SVGStylable, SVGFitToViewBox,events::
EventTarget { };
interface SVGUseElement : SVGElement,SVGElement,
SVGURIReference,SVGURIReference,
SVGTests, SVGLangSpace, SVGExternalResourcesRequired, SVGStylable, SVGTransformable,events::
EventTarget {
readonly attribute SVGAnimatedLength
x; readonly attribute SVGAnimatedLength
y; readonly attribute SVGAnimatedLength
width; readonly attribute SVGAnimatedLength
height; readonly attribute SVGElementInstance instanceRoot; readonly attribute SVGElementInstance animatedInstanceRoot; };
For each 'use' element, the SVG DOM maintains a shadow tree (the "instance tree") of objects of type SVGElementInstance. A An SVGElementInstance represents a single node in the instance tree. The root object in the instance tree is pointed to by the instanceRoot attribute on the SVGUseElement object for the corresponding 'use' element.
If the 'use' element references a simple graphics element such as a 'rect', then there is only a single SVGElementInstance object, and the correspondingElement attribute on this SVGElementInstance object is the SVGRectElement that corresponds to the referenced 'rect' element.
If the 'use' element references a 'g' which contains two 'rect' elements, then the instance tree contains three SVGElementInstance objects, a root SVGElementInstance object whose correspondingElement is the SVGGElement object for the 'g', and then two child SVGElementInstance objects, each of which has its correspondingElement that is an SVGRectElement object.
If the referenced object is itself a 'use', or if there are 'use' subelements within the referenced object, the instance tree will contain recursive expansion of the indirect references to form a complete tree. For example, if a 'use' element references a 'g', and the 'g' itself contains a 'use', and that 'use' references a 'rect', then the instance tree for the original (outermost) 'use' will consist of a hierarchy of SVGElementInstance objects, as follows:
SVGElementInstance #1 (parentNode=null, firstChild=#2, correspondingElement is the 'g') SVGElementInstance #2 (parentNode=#1, firstChild=#3, correspondingElement is the other 'use') SVGElementInstance #3 (parentNode=#2, firstChild=null, correspondingcorrespondingElement Element is the 'rect')IDL Definition
interface SVGElementInstance :events::
EventTarget {
readonly attribute SVGElement correspondingElement; readonly attribute SVGUseElement correspondingUseElement; readonly attribute SVGElementInstance parentNode; readonly attribute SVGElementInstanceList childNodes; readonly attribute SVGElementInstance firstChild; readonly attribute SVGElementInstance lastChild; readonly attribute SVGElementInstance previousSibling; readonly attribute SVGElementInstance nextSibling; };
interface SVGElementInstanceList { readonly attribute unsigned long length; SVGElementInstance item
(
in unsigned long index
);
};
interface SVGImageElement : SVGElement,SVGElement,
SVGURIReference,SVGURIReference,
SVGTests, SVGLangSpace, SVGExternalResourcesRequired, SVGStylable, SVGTransformable,events::
EventTarget {
readonly attribute SVGAnimatedLength x; readonly attribute SVGAnimatedLength y; readonly attribute SVGAnimatedLength width; readonly attribute SVGAnimatedLength height; readonly attribute SVGAnimatedPreserveAspectRatio preserveAspectRatio; };
interface SVGSwitchElement : SVGElement,SVGElement,
SVGTests,SVGTests,
SVGLangSpace, SVGExternalResourcesRequired, SVGStylable, SVGTransformable,events::
EventTarget { };
interface GetSVGDocument {
SVGDocument getSVGDocument
(
)
raises(
DOMException
);
};