XML technologies / SVG / SVG basics and possible applications / What is SVG? / XML versus SVG?
(Excerpt from “Das Einsteigerseminar SVG — Webgrafiken mit XML” by Helma Spona)
XML and SVG files look very similar, as these listings show: first a simple XML file, then an SVG file.
<?xml version="1.0" encoding="UTF-8"?>
<dataroot>
<adressen>
<ID>1</ID>
<Nachname>Maier</Nachname>
<Vorname>Franz</Vorname>
<Ort>Irgendwo</Ort>
</adressen>
</dataroot>
This SVG file defines a rectangle with a fill color
<?xml version="1.0" encoding="iso-8859-1"?>
<!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 20001102//EN" "http://www.w3.org/TR/2000/CR-SVG-20001102/DTD/svg-20001102.dtd">
<svg xml:space="preserve">
<rect y="10" x="10" width="30" height="15" style="fill:orange;stroke:black"/>
</svg>The differences lie in details. Both begin by specifying the XML version with the line <?xml version="1.0". The encoding attribute sets the encoding. It differs here, but SVG can use the same encoding as XML.
The main difference follows: SVG includes the <DOCTYPE> declaration, telling the browser to interpret the file as SVG and display it as graphics.
Both then contain XML tags, depending on whether the file is plain XML, XML with a DTD, or SVG. The DTD (DocType Definition) determines allowed tags and attributes. Omitting the <DOCTYPE> declaration may still display SVG correctly because the extension identifies it as an SVG graphic. The SVG standard nevertheless requires the <DOCTYPE> declaration, so strictly conforming programs may report an error if it is missing.
Note:
XML files can also use the <DOCTYPE> declaration to specify a DTD defining tags and attributes. Plain XML does not necessarily need it to produce a valid document.
The XML document’s top-level element begins with <dataroot>; in SVG, it must be <svg>. Without a DTD, the XML file’s tags can be renamed, but SVG’s cannot: its DTD fixes the allowed elements.
Note:
For example, convert SVG into XML by removing the <DOCTYPE> declaration and changing the extension from SVG to XML. The browser then treats it as XML. XSL documents can also convert XML to SVG, changing both its outer form and contents.
Copyright © verlag moderne industrie GmbH 2001
You may print the online version for your private use.
Otherwise, this chapter from “Das Einsteigerseminar SVG — Webgrafiken mit XML” is subject to the same conditions as the bound edition. The work, including all its parts, is protected by copyright. All rights reserved, including reproduction, translation, microfilming, and storage and processing in electronic systems.
verlag moderne industrie GmbH, Justus-von-Liebig-Straße 1, D-86899 Landsberg/Lech, fon ++49 (0) 81 91 / 125 – 0, leserservice(at)mi-verlag.de
back to top