5

Upgraded to 20.04 today and, somehow, Document Viewer is not able to open .svg files. It keeps giving this error. Previously, when I was using 18.04, everything was working fine. No such errors I encountered.

XML parse error: error code=201 (3) in (null):606:15: Namespace prefix xlink for href on image is not defined

EDIT

<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 20010904//EN"
  "http://www.w3.org/TR/2001/REC-SVG-20010904/DTD/svg10.dtd">
<svg width="200" height="200">
  <image id="image0" width="200" height="200" x="0" y="0"
    xlink:href="data:image/png;base64
C.S.
  • 329

2 Answers2

6

Your document viewer complains about the svg file having an xlink notation somewhere without being declared. As such, your svg file is not a valid xml and the document viewer complains correctly. Maybe in the newer version it is more strict about it.

To fix your file open it with an editor and make sure the xlink declaration is included in the <svg> tag in the very beginning of your file, it should look something like this:

<svg xmlns="http://www.w3.org/2000/svg"
     xmlns:xlink="http://www.w3.org/1999/xlink">

Update: For your file, change this line:

<svg width="200" height="200">

to this:

<svg width="200" height="200"
     xmlns="http://www.w3.org/2000/svg"
     xmlns:xlink="http://www.w3.org/1999/xlink">
pLumo
  • 26,947
  • Alternatively, for SVG 2.0, you don't need any of that, and can use the href attribute directly: https://developer.mozilla.org/en-US/docs/Web/SVG/Attribute/href – Ismael Miguel Aug 07 '20 at 16:42
4

See: <svg> - SVG: Scalable Vector Graphics | MDN

The svg element is a container that defines a new coordinate system and viewport. It is used as the outermost element of SVG documents, but it can also be used to embed a SVG fragment inside an SVG or HTML document.

Note: The xmlns attribute is only required on the outermost svg element of SVG documents. It is unnecessary for inner svg elements or inside HTML documents.


It is enough in most cases the svg tag to have the following attributes: xmlns and viewBox; optionally width and height:

<svg xmlns="http://www.w3.org/2000/svg"
     viewBox="0 0 16 16" width="50" height="50">
  <g>
    <path d=". . ."></path>
  </g>
</svg>
Zanna
  • 70,465