XML technologies / SVG / Adding hyperlinks and external files / Including external files / Using parts of an external SVG graphic

(Excerpt from “Das Einsteigerseminar SVG — Webgrafiken mit XML” by Helma Spona)

Certain SVG tags can reference parts of an SVG graphic for use in other SVG files. SVG provides the <use> tag for this, allowing elements defined with <svg>, <g>, <symbol> or basic SVG graphic elements such as <rect>, <line>, <circle> and so on. Any named element can thus serve as a template, creating a copy with <use>. Again, specify the address or element name with the xlink:href attribute.

Note:
SVG supports references to elements in other SVG files using absolute or relative paths. Adobe SVG Viewer, however, allows only elements in the current file; versions 1.0 and 2.0 do not yet support external references. The next example nevertheless shows how this should work.

<?xml version="1.0" standalone="no"?>
...
<svg width="430" height="330">
  <use x="20" y="20" xlink:href="symbolBttn.svg#bttn" />
</svg>

The preceding listing displays the element bttn from the file symbolBttn.svg by embedding it with the <use> tag. The element bttn must be defined as a <symbol>, <g> or <svg> tag. Test this with Batik 1.0, producing the following result.

External SVG button symbol displayed in Batik

Figure: External SVG button symbol displayed in Batik.

   

 

 

 

back to top