XML technologies / SVG / Using text elements / Special text formatting / Using special characters and umlauts

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

Text often needs umlauts such as ä or ü, or special characters such as © or ™. Simply typing umlauts into the <text> tag causes a syntax error.

Umlauts in text cause syntax errors

Figure: Umlauts in text cause syntax errors.

Such errors usually display text only up to the offending character. In the example, this is the ö in können.

Two methods are available, depending on whether you need ordinary umlauts and accented letters or special characters such as ® and ©. Normal character-set characters can be entered through their ASCII codes, including German umlauts and ß. For each, enter &#Nummer;, where Nummer represents the character’s ASCII code.

Some special characters, such as &, also accept HTML encodings. In this case, enter &amp;. Only a few characters support HTML encodings; most require ASCII codes.

<?xml version="1.0" standalone="no"?>
...
<svg width="500" height="500">
  <defs>
    <text id="cr">(c) 2001 by Helma Spona</text>
    <text id="titel">Die Webseite zum Buch: SVG - Scalable Vector Graphic</text>  
  </defs>
  <g style="font-size:18;font-family:serif">
    <text x="10" y="20">Auch Sonderzeichen und Umlaute k&#246;nnen Sie nat&#252;rlich in</text>
    <text x="10" y="35">SVG-Texten verwenden. &#10;Dazu stehen wahlweise ASCII-Codes </text>
    <text x="10" y="50">oder HTML-Codes bspw. f&#252;r die Zeichen &#169;, &#174; und &amp; zur</text>
    <text x="10" y="65">Verf&#252;gung.</text>
  </g>
</svg>

Text with special characters

Figure: Text with special characters.

The table lists ASCII codes for important umlauts and special characters.

Table: Important ASCII codes for special characters.

Character

ASCII code

Ä

196

ä

228

Ö

214

ö

246

Ü

220

ü

252

ß

223

§

167

®

174

©

169

Entering umlauts this way is laborious, especially in long texts. Specify the SVG file’s character encoding instead. With the correct code page, enter German umlauts and special characters normally without their ASCII codes.

Put the following on the SVG file’s first line: <?xml version="1.0" encoding="iso-8859-1"?> This specifies the encoding.

   

 

 

 

back to top