下面是一个简单的SVG的例子(Example1.svg),其中一个自定义元素(<myNS:HelloWorld/>)要求获得由文件顶部的元素所定义的交替表示行为。通过使用绑定所附加的影子树的内容,可以生成<myNS:HelloWorld/>元素。影子树包括一个<svg:text>元素,其中带有“Hello, world, using sXBL”字符串:
Example1.svg
<?xml version="1.0"?> <svg width="10cm" height="3cm" viewBox="0 0 200 60" xmlns="http://www.w3.org/2000/svg" version="1.2" xmlns:xbl="http://www.w3.org/2004/xbl" xmsns:myNS="http://www.example.com"> <title>Example example1.svg - "hello world" sample file</title> <desc>A simple "Hello, world" sXBL example where the rendering behavior of a custom element 'myNS:HelloWorld' consists of an 'svg:text' element which has the string "Hello, world, using sXBL" inside.</desc> <defs>
<xbl:xbl>
<!-- The following 'xbl:definition' element defines the presentation and interactive behavior that must be used for all 'myNS:HelloWorld' elements in this document. --> <xbl:definition element="myNS:HelloWorld> <xbl:template> <text>Hello, world, using sXBL</text>
<!-- Here is an instance of an 'myNS:HelloWorld' element. The above binding definition attaches a shadow tree which defines alternative rendering and interactive behavior for this element. Instead of the standard SVG behavior where unknown elements are not rendered, the binding definition causes an 'svg:text' element to be rendered. --> <myNS:HelloWorld/>