SVG Namespace prefix xlink for href on image is not defined

kabrice picture kabrice · Dec 2, 2019 · Viewed 10k times · Source

I've an svg content that looks a bit like this:

<svg height="1000" preserveaspectratio="xMidYMid meet" style="width: 100%; height: 100%; transform: translate3d(0px, 0px, 0px);" viewbox="0 0 1000 1000" width="1000"
    xmlns="http://www.w3.org/2000/svg">
    <defs>
        <clippath id="__lottie_element_2">
            <rect height="1000" width="1000" x="0" y="0"></rect>
        </clippath>
        <clippath id="__lottie_element_4">
            <path d="M0,0 L3048,0 L3048,2431 L0,2431z"></path>
        </clippath>
    </defs>
    <g clip-path="url(#__lottie_element_2)">
        <g clip-path="url(#__lottie_element_4)" opacity="1" style="display: block;" transform="matrix(0.5006899833679199,0,0,0.5006899833679199,-263.051513671875,-180.58868408203125)">
            <g class="H01 2k" opacity="1" style="display: block;" transform="matrix(0.9999813437461853,0.006108480971306562,-0.006108480971306562,0.9999813437461853,504.42333984375,488.25836181640625)">
                <image height="1442px" preserveaspectratio="xMidYMid slice" width="2048px" xlink:href="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAACAA...MC2S3oHLwAAAABJRU5ErkJggg=="></image>
            </g>
            <g opacity="1" style="display: block;" transform="matrix(0.9947565197944641,-0.10227109491825104,0.10227109491825104,0.9947565197944641,452.203369140625,619.6126708984375)">
                <image height="1442px" preserveaspectratio="xMidYMid slice" width="2048px" xlink:href="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAACAAA...BJRU5ErkJggg=="></image>
            </g>
            <g opacity="1" style="display: block;" transform="matrix(0.9999813437461853,0.006108480971306562,-0.006108480971306562,0.9999813437461853,504.40704345703125,490.92486572265625)">
                <image height="1442px" preserveaspectratio="xMidYMid slice" width="2048px" xlink:href="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAACAAAAAWiCAYA...3+XcSAElFTkSuQmCC"></image>
            </g>
            <g opacity="1" style="display: block;" transform="matrix(0.9999813437461853,0.006108480971306562,-0.006108480971306562,0.9999813437461853,504.42333984375,488.25836181640625)">
                <image height="1442px" preserveaspectratio="xMidYMid slice" width="2048px" xlink:href="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAACAAAAAWiCA...AAASUVORK5CYII="></image>
            </g>
        </g>
    </g>
</svg>

Here is the original file.

But Whenever I try to display it through my browser, I get this error :

This page contains the following errors:
error on line 1 at column 982067: Namespace prefix xlink for href on image is not defined
Below is a rendering of the page up to the first error.

And I don't know why. Please what's wrong ?

Answer

Sirko picture Sirko · Dec 2, 2019

The <svg> element is missing the declaration of the xlink namespace, although it is used in the <image> elements. So just added like the following:

<svg height="1000" preserveaspectratio="xMidYMid meet" style="width: 100%; height: 100%; transform: translate3d(0px, 0px, 0px);" viewbox="0 0 1000 1000" width="1000"
    xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink">

SVG2 deprecated the xlink namespace for href attributes.. So in the future, changing xlink:href="..." to href="..." would be the better solution.