©
Ce document utiliseManuel du site Web PHP chinoisLibérer
SVG allows inclusion of elements from foreign namespaces anywhere with the SVG content. In general, the SVG user agent will include the unknown elements in the DOM but will otherwise ignore unknown elements. (The notable exception is described under Embedding Foreign Object Types.)
Additionally, SVG allows inclusion of attributes from foreign namespaces on any SVG element. The SVG user agent will include unknown attributes in the DOM but with otherwise ignore unknown attributes.
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:
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 at a given point within the SVG content tree. One particular example of this is to provide a frame for XML content styled with CSS or XSL so that dynamically reflowing text (subject to SVG transformations and compositing) could be inserted into the middle of some SVG content. Another example is inserting a MathML expression into an SVG drawing [MATHML].
The‘foreignObject’element allows for inclusion of a foreign namespace which has its graphical content drawn by a different user agent. The included foreign graphical content 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 with a proper‘xmlns’(seeNamespaces in XML[XML-NS]) attribute specification is embedded recursively. One situation where this can occur is when an SVG document fragment is embedded within another non-SVG document fragment, which in turn is embedded within an SVG document fragment (e.g., an SVG document fragment contains an XHTML document fragment which in turn contains yet another SVG document fragment).
Usually, a‘foreignObject’will be used in conjunction with the‘switch’element and the‘requiredExtensions’attribute to provide proper checking for user agent support and provide an alternate rendering in case user agent support is not available.
Attribute definitions:
Here is an 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 must 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 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 capability is not a requirement.
Using foreign namespaces as an extension mechanism adds flexibility, is readily handled by validation technologies like NVDL and RelaxNG, but typically breaks DTD validation unless the DTD has explicit extensibility hooks.
The SVG DTD allows for extending the SVG language within the internal DTD subset. Within the internal DTD subset, you have the ability to add custom elements and attributes to most SVG elements. This facility may be used if DTD validation is desired.
The DTD defines an extension entity for most of SVG elements. For example, the‘view’element is defined in the DTD as follows:
]]> ]]>
The entitySVG.view.extra.content
can be defined in the internal DTD subset to add custom sub-elements attributes to the‘view’element within a given document, and ancan be used to add custom attributes. For example, the following extends the‘view’element with an additional child element‘customNS:customElement’and an additional attribute‘customNS:customAttr’:
]>
interfaceSVGForeignObjectElement: SVGElement, SVGTests, SVGLangSpace, SVGExternalResourcesRequired, SVGStylable, SVGTransformable { readonly attribute SVGAnimatedLength x; readonly attribute SVGAnimatedLength y; readonly attribute SVGAnimatedLength width; readonly attribute SVGAnimatedLength height; };