views:

27

answers:

1

Hi,

Is there a way to attach metadata directly to a grouping element () in an svg file? I couldn't find anything about that in the specification or elsewhere on the web, so I assume it's not possible. Perhaps there are other ways to attach element specific metadata within the svg file...

What I try to do is to create a map and attach information about adjacent countries.

Cheers.

+1  A: 

As XML is extensible you can add attributes and element children as you wish. Here's a possible example:

<svg xmlns="http://www.w3.org/2000/svg" xmlns:sol="http://www.sol.org"&gt;
  <circle cx="10" cy="20" sol:country="ruritania" r="5"/>
</svg>

Here the svg and circle elements are in SVG namespace and sol:country is in your namespace. I believe that SVG user agents will ignore foreign namespaces. You could also use a metadata schem such as Dublin Core.

Alternatively you could use a desc element (http://www.w3.org/TR/SVG/struct.html#DescElement)


5.4 The 'desc' and 'title' elements

Each container element or graphics element in an SVG drawing can supply a 'desc' and/or a 'title' description string where the description is text-only. When the current SVG document fragment is rendered as SVG on visual media, 'desc' and 'title' elements are not rendered as part of the graphics. User agents may, however, for example, display the 'title' element as a tooltip, as the pointing device moves over particular elements. Alternate presentations are possible, both visual and aural, which display the 'desc' and 'title' elements but do not display 'path' elements or other graphics elements. This is readily achieved by using a different (perhaps user) style sheet. For deep hierarchies, and for following 'use' element references, it is sometimes desirable to allow the user to control how deep they drill down into descriptive text.

peter.murray.rust
Great solutions. I might go with the 2nd one. I didn't even look at the desc element as I thought it applies to the metadata element only as description for the whole file. Thanks.
sol