Metadata in SVG

Discuss SVG code, accessible via the XML Editor.
joachim
Posts: 1
Joined: Sun Sep 13, 2009 10:29 pm

Metadata in SVG

Postby joachim » Mon Sep 14, 2009 12:00 am

General Description of the Problem
To my be honest I am not very familiar with SVG details. Thus , I hope an expert can easiliy help me to solve the subsequent problem.

The SVG1.1-DTD http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd with Structure module
http://www.w3.org/Graphics/SVG/1.1/DTD/svg-structure.mod specifies the metadata element in the following way:

Code: Select all

<!-- metadata: Metadata Element ........................ -->

<!ENTITY % SVG.metadata.extra.content "" >

<!ENTITY % SVG.metadata.element "INCLUDE" >
<![%SVG.metadata.element;[
<!ENTITY % SVG.metadata.content
    "( #PCDATA %SVG.metadata.extra.content; )*"
>
<!ELEMENT %SVG.metadata.qname; %SVG.metadata.content; >

My problem is to extend the metadata element description and its name space in SVG. How and where the metadata "extension" (metadata child) can be described? Let me add some examples to explain this.

Example from W3 sites
On the W3 sites an example with metadata element extensions (metadata child) is given (see section 21.3 http://www.w3.org/TR/SVG/metadata.html#InterfaceSVGMetadataElement):

Code: Select all

<?xml version="1.0" standalone="yes"?>
<svg width="4in" height="3in" version="1.1"
    xmlns = 'http://www.w3.org/2000/svg'>
    <desc xmlns:myfoo="http://example.org/myfoo">
      <myfoo:title>This is a financial report</myfoo:title>
      <myfoo:descr>The global description uses markup from the
        <myfoo:emph>myfoo</myfoo:emph> namespace.</myfoo:descr>
      <myfoo:scene><myfoo:what>widget $growth</myfoo:what>
      <myfoo:contains>$three $graph-bar</myfoo:contains>
        <myfoo:when>1998 $through 2000</myfoo:when> </myfoo:scene>
   </desc>
    <metadata>
      <rdf:RDF
           xmlns:rdf = "http://www.w3.org/1999/02/22-rdf-syntax-ns#"
           xmlns:rdfs = "http://www.w3.org/2000/01/rdf-schema#"
           xmlns:dc = "http://purl.org/dc/elements/1.1/" >
        <rdf:Description about="http://example.org/myfoo"
             dc:title="MyFoo Financial Report"
             dc:description="$three $bar $thousands $dollars $from 1998 $through 2000"
             dc:publisher="Example Organization"
             dc:date="2000-04-11"
             dc:format="image/svg+xml"
             dc:language="en" >
          <dc:creator>
            <rdf:Bag>
              <rdf:li>Irving Bird</rdf:li>
              <rdf:li>Mary Lambert</rdf:li>
            </rdf:Bag>
          </dc:creator>
        </rdf:Description>
      </rdf:RDF>
    </metadata>
</svg>

It is not described where the rdf metadata extension is carried out. I could validate an associated file as XML compatible but not SVG compatible using the W3 validator http://validator.w3.org/.

Example with extended DTD
The following SVG code can be validated. But it is required not to include the DTD extension into the SVG file. How this can be done and how the DTD can be replaced by a schema:

Code: Select all

<?xml version="1.0" standalone="no"?>
<!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN" "http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd"
[
<!ENTITY % SVG.metadata.extra.content "|meta" >
<!ELEMENT meta (#PCDATA) >
<!ATTLIST meta name CDATA #REQUIRED>
]
>
<svg width="20cm" height="20cm" viewBox="-150 -50 300 500" version="1.1" xmlns="http://www.w3.org/2000/svg">
   <title>Resistor</title>
   <desc>From spice2vhd library</desc>
   <metadata>
      <meta name="Name">Resistor</meta>
      <meta name="Library">spice2vhd</meta>
      <meta name="Architecture">SPICE</meta>
   </metadata>
   
   <g class="Port">
      <metadata>
         <meta name="PortClass">terminal</meta>
         <meta name="PortType">Electrical</meta>
         <meta name="Name">P</meta>
         <meta name="X">0</meta>
         <meta name="Y">0</meta>
      </metadata>
      <text x="0" y="0" font-size="12" font-family="Arial" font-style="normal" fill="#0000ff">P</text>
   </g>
</svg>


How to use name space extensions
The solution for the last example should look like:

Code: Select all

<?xml version="1.0" standalone="no"?>
<!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN" "http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd">

<svg width="20cm" height="20cm" viewBox="-150 -50 300 500" version="1.1" xmlns="http://www.w3.org/2000/svg">
   <title>Resistor</title>
   <desc>From spice2vhd library</desc>
   <metadata>
      
     <my:my xmlns:my="http://intranet/my_meta">
      <my:meta name="Name">Resistor</my:meta>
      <my:meta name="Library">spice2vhd</my:meta>
      <my:meta name="Architecture">SPICE</my:meta>   
          </my:my>   

   </metadata>
   
   <g class="Port">
      <metadata>
      
         <my:my xmlns:my="http://intranet/my_meta">
        <my:meta name="PortClass">terminal</my:meta>
        <my:meta name="PortType">Electrical</my:meta>
        <my:meta name="Name">P</my:meta>
        <my:meta>name="X">0</my:meta>
        <my:meta>name="Y">0</my:meta>
              </my:my>   

       </metadata>
       <text x="0" y="0" font-size="12" font-family="Arial" font-style="normal" fill="#0000ff">P</text>
   </g>
</svg>

with a schema my_meta.xsd

Code: Select all

<?xml version="1.0" encoding="UTF-8"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" elementFormDefault="qualified" attributeFormDefault="unqualified">
   <xs:element name="meta">
      <xs:annotation>
         <xs:documentation>Meta data element for use in Namespace</xs:documentation>
      </xs:annotation>
      <xs:complexType>
         <xs:attribute name="name" type="xs:string" use="required"/>
      </xs:complexType>
   </xs:element>
</xs:schema>

Thanks in advance for any helpful hints.

dominik.holler
Posts: 1
Joined: Fri Nov 27, 2009 7:29 pm

Re: Metadata in SVG

Postby dominik.holler » Fri Nov 27, 2009 7:48 pm

Why do you want to create "valid SVG"?
I do not know how exacytly "valid svg" is defined. From my point of view it is enough to create valid xml with an svg root element. For an example see an svg produced by inkscape.

If you are embedding application data in svg, you are in conflict with patent 5787449 (http://www.google.com/patents?id=y8UkAAAAEBAJ) ?


Return to “SVG / XML Code”