17 Extensibility



17.1 Foreign Namespaces and Private Data

SVG allows inclusion of elements from foreign namespaces anywhere with the SVG document tree. In general, the SVG user agent will ignore any unknown elements except to include them within the DOM. (The notable exception is described under Embedding Foreign Object Types.)

SVG's ability to include foreign namespaces can be used for the following purposes:

To illustrate, a business graphics authoring application might want to include some private data within an SVG document so that it could properly reassemble the chart (a pie chart in this case) upon reading it back in:

<?xml version="1.0" standalone="yes"?>
<svg width="4in" height="3in"
     xmlns = 'http://www.w3.org/Graphics/SVG/svg-19990730.dtd'>
    <myapp:piechart xmlns:myapp="http://mycompany/mapapp"
                    title="Sales by Region">
      <myapp:pieslice label="Northern Region" value="1.23"/>
      <myapp:pieslice label="Eastern Region" value="2.53"/>
      <myapp:pieslice label="Southern Region" value="3.89"/>
      <myapp:pieslice label="Western Region" value="2.04"/>
      <!-- Other private data goes here -->
  <desc>This chart includes private data in another namespace
  <!-- In here would be the actual graphics elements which
       draw the pie chart -->

Download this example

17.2 Embedding Foreign Object Types

One goal for SVG is to provide a mechanism by which other XML language processors can render into an area within an SVG drawing, with those renderings subject to the various transformations and compositing parameters that are currently active within the SVG document. One particular example of this is to provide a frame for the HTML/CSS processor so that dynamically reflowing text (subject to SVG transformations and compositing) could be inserted into the middle of an SVG document. Another example is inserting a MathML expression into an SVG drawing.

The <foreignObject> element allows for inclusion of foreign namespaces which has graphical content drawn by a different user agent, where the graphical content that is drawn is subject to SVG transformations and compositing. The contents of <foreignObject> are assumed to be from a different namespace. Any SVG elements within a <foreignObject> will not be drawn, except in the situation where a properly defined SVG subdocument is recursively embedded within the different namespace (e.g., an SVG document contains an XHTML document which in turn contains yet another SVG document).

Additionally, there is a capability for alternative representations so that something meaningful will appear in SVG viewing environments which do not have the ability to process a given <foreignObject>. To accomplish this, SVG has a <switch> element and system-required attribute similar to the corresponding facilities within the SMIL 1.0 Recommendation. The rules for <switch> are that the first child element whose system-required evaluates to "true" will be processed and all others ignored.

Here is an example:

<?xml version="1.0" standalone="yes"?>
<svg width="4in" height="3in"
 xmlns = 'http://www.w3.org/Graphics/SVG/svg-19990730.dtd'>
  <desc>This example uses the switch element to provide a 
  fallback graphical representation of an equation, if 
  MathML is not supported.
  <!-- The <switch> element will process the first child element
       whose testing attributes evaluate to true.-->

    <!-- Process the MathML if the system-required attribute
         evaluates to true (i.e., the user agent supports MathML
         embedded within SVG). -->
       width="100" height="50">
      <!-- MathML content goes here -->

    <!-- Else, process the following alternate SVG.
         Note that there are no testing attributes on the <g> element.
         If no testing attributes are provided, it is as if there
         were testing attributes and they evaluated to true.-->
      <!-- Draw a red rectangle with a text string on top. -->
      <rect style="fill: red"/>
      <text>Formula goes here</text>


Download this example

It is not required that SVG user agent support the ability to invoke other arbitrary user agents to handle embedded foreign object types; however, all conforming SVG user agents would need to support the <switch> element and should be able to render valid SVG elements when they appear as one of the alternatives within a <switch> element.

Ultimately, it is expected that commercial Web browsers will support the ability for SVG to embed content from other XML grammars which use CSS layout or XSL to format their content, with the resulting CSS- or XSL-formatted content subject to SVG transformations and compositing. At this time, such a feature represents an objective, not a requirement.

(The exact mechanism for providing these capabilities hasn't been decided yet. Many details need to be worked out.)

Definition of system-required:

17.3 The system-required attribute

system-required = feature
Determines whether the named feature is supported by the user agent. If the given feature is supported, then the current element and its children are processed; otherwise, the current element and its children are ignored.