Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bug, attribute name "prefixes" are dropped #5

Open
JoakimSoderberg opened this issue Mar 26, 2018 · 6 comments
Open

Bug, attribute name "prefixes" are dropped #5

JoakimSoderberg opened this issue Mar 26, 2018 · 6 comments

Comments

@JoakimSoderberg
Copy link

Reading this XML file (an SVG) and then simply resaving it will write invalid characters in the CSS part.

The error that chrome gives on trying to read this SVG

This page contains the following errors:
error on line 2 at column 457: Attribute version redefined
Below is a rendering of the page up to the first error.

Line 2:
original

<svg
   xmlns:dc="http://purl.org/dc/elements/1.1/"
   xmlns:cc="http://creativecommons.org/ns#"
   xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
   xmlns:svg="http://www.w3.org/2000/svg"
   xmlns="http://www.w3.org/2000/svg"
   xmlns:sodipodi="http://sodipodi.sourceforge.net/DTD/sodipodi-0.dtd"
   xmlns:inkscape="http://www.inkscape.org/namespaces/inkscape"
   id="Logo"
   width="2139"
   height="2139"
   viewBox="0 0 2139 2139"
   version="1.1"
   sodipodi:docname="siknas07-alt03.svg"
   inkscape:version="0.92.1 r15371"
   inkscape:label="Cirkel">

rewritten file

<svg dc="http://purl.org/dc/elements/1.1/" cc="http://creativecommons.org/ns#" rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" svg="http://www.w3.org/2000/svg" xmlns="http://www.w3.org/2000/svg" sodipodi="http://sodipodi.sourceforge.net/DTD/sodipodi-0.dtd" inkscape="http://www.inkscape.org/namespaces/inkscape" id="Logo" width="2139" height="2139" viewBox="0 0 2139 2139" version="1.1" docname="siknas07-alt03.svg" version="0.92.1 r15371" label="Cirkel">

Seems like all prefixes are dropped from the attribute names, resulting in duplicate version:

version="1.1"
inkscape:version="0.92.1 r15371"

Becomes

version="1.1"
version="0.92.1 r15371"

Small program to reproduce this:

package main

import (
	"fmt"
	xmldom "github.com/subchen/go-xmldom"
)

var svgData = `
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<svg
   xmlns:dc="http://purl.org/dc/elements/1.1/"
   xmlns:cc="http://creativecommons.org/ns#"
   xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
   xmlns:svg="http://www.w3.org/2000/svg"
   xmlns="http://www.w3.org/2000/svg"
   xmlns:sodipodi="http://sodipodi.sourceforge.net/DTD/sodipodi-0.dtd"
   xmlns:inkscape="http://www.inkscape.org/namespaces/inkscape"
   id="Logo"
   width="2139"
   height="2139"
   viewBox="0 0 2139 2139"
   version="1.1"
   sodipodi:docname="siknas07-alt03.svg"
   inkscape:version="0.92.1 r15371"
   inkscape:label="Cirkel">
  <metadata
     id="metadata30">
    <rdf:RDF>
      <cc:Work
         rdf:about="">
        <dc:format>image/svg+xml</dc:format>
        <dc:type
           rdf:resource="http://purl.org/dc/dcmitype/StillImage" />
        <dc:title></dc:title>
      </cc:Work>
    </rdf:RDF>
  </metadata>
  <sodipodi:namedview
     pagecolor="#ffffff"
     bordercolor="#666666"
     borderopacity="1"
     objecttolerance="10"
     gridtolerance="10"
     guidetolerance="10"
     inkscape:pageopacity="0"
     inkscape:pageshadow="2"
     inkscape:window-width="1280"
     inkscape:window-height="961"
     id="namedview28"
     showgrid="false"
     inkscape:zoom="0.15603291"
     inkscape:cx="160.60893"
     inkscape:cy="1292.5084"
     inkscape:window-x="-8"
     inkscape:window-y="616"
     inkscape:window-maximized="1"
     inkscape:current-layer="g4553" />
  <defs
     id="defs4">
    <style
       id="style2">
      .cls-1 {
        fill: #35462d;
      }

      .cls-1, .cls-2, .cls-3, .cls-5 {
        fill-rule: evenodd;
      }

      .cls-2, .cls-5 {
        fill: none;
        stroke-width: 20px;
      }

      .cls-2 {
        stroke: #90a3bc;
      }

      .cls-3 {
        fill: #90a3bc;
      }

      .cls-4 {
        opacity: 0.08;
        mix-blend-mode: difference;
      }

      .cls-5 {
        stroke: #296d69;
      }
    </style>
    <clipPath
       clipPathUnits="userSpaceOnUse"
       id="clipPath4562">
      <circle
         cx="1069.5"
         cy="1069.5"
         r="1069.5"
         id="circle4564" />
    </clipPath>
    <clipPath clipPathUnits="userSpaceOnUse" id="SiknasClipPath">
      <path
         id="iknäs_road_as_shape"
         data-name="iknäs road as shape"
         class="cls-1"
         d="m 904.1,808.61 q 3.732,-10.218 -1.036,-24.787 -5.137,-15.688 -13.775,-20.719 -8.638,-5.031 -20.777,-1.055 a 32.915,32.915 0 0 0 -9.84,4.98 19.527,19.527 0 0 0 -6.038,7.56 24.406,24.406 0 0 0 -1.859,10.742 52.626,52.626 0 0 0 2.918,14.658 q 4.953,15.129 14.078,20.827 9.125,5.698 20.455,1.988 12.136,-3.975 15.874,-14.194 z m 59.183,315.12 40.952,-13.41 -84.217,-257.188 -40.954,13.41 z m 84.282,-27.85 40.19,-15.55 -48.455,-125.185 1.27,-0.492 94.52,107.357 40.98,-15.87 -106.21,-116.313 3.92,-134.282 -38.6,14.94 -0.92,127.856 -1.28,0.491 -74.268,-191.9 -40.188,15.555 z m 148.23,-59.63 40.51,-14.69 -74.62,-205.823 a 44.962,44.962 0 0 1 6.02,-16.61 q 4.335,-6.793 10.42,-9 8.64,-3.135 15.51,1.8 6.87,4.935 12.96,21.747 l 70.06,193.259 40.52,-14.683 -70.685,-194.93 q -11.31,-31.223 -27.46,-43.035 -16.15,-11.812 -35.53,-4.785 a 55.687,55.687 0 0 0 -11.71,5.92 46.331,46.331 0 0 0 -10.28,9.371 56.856,56.856 0 0 0 -8.07,13.482 74.758,74.758 0 0 0 -5.07,18.249 l -0.07,-0.185 -13.53,-25.825 -31.22,11.321 z m 222.33,-77.036 a 56.041,56.041 0 0 0 13.01,-23.121 l 9.07,21.559 30.89,-8.451 -53.485,-195.441 a 152.848,152.848 0 0 0 -10.96,-29.4 q -6.225,-12.147 -15.22,-18.859 a 41.677,41.677 0 0 0 -21.33,-7.918 q -12.345,-1.207 -29.26,3.423 a 72.8,72.8 0 0 0 -22.76,10.4 53.056,53.056 0 0 0 -15.51,16.571 53.964,53.964 0 0 0 -7.02,22.094 q -1.29,12.378 2.7,26.972 a 106.08,106.08 0 0 0 4.09,12.024 q 2.415,5.961 5.92,12.947 l 31.71,-8.676 -3.11,-11.374 a 82.293,82.293 0 0 1 -3.25,-19.284 37.625,37.625 0 0 1 1.78,-13.525 19.061,19.061 0 0 1 5.63,-8.469 21.489,21.489 0 0 1 8.1,-4.256 q 6.57,-1.8 11.1,-0.083 a 17.187,17.187 0 0 1 7.75,6.032 40.851,40.851 0 0 1 5.49,10.722 q 2.28,6.4 4.36,13.987 l 9.44,34.5 q -5.355,4.322 -12.14,10.149 -6.785,5.827 -12.05,11.142 a 160.833,160.833 0 0 0 -18.56,21.888 88.407,88.407 0 0 0 -11.51,22.817 81.212,81.212 0 0 0 -3.93,25.323 112.178,112.178 0 0 0 4.38,29.568 106.22,106.22 0 0 0 9.7,24.141 65.08,65.08 0 0 0 13.88,17.5 44.2,44.2 0 0 0 17.33,9.42 37.074,37.074 0 0 0 19.96,-0.268 49.405,49.405 0 0 0 23.8,-14.054 z m -34.26,-32.6 q -7.59,-7.7 -11.68,-22.681 a 71.891,71.891 0 0 1 -2.75,-18.1 65.4,65.4 0 0 1 1.56,-15.607 52.613,52.613 0 0 1 4.68,-12.895 64.545,64.545 0 0 1 6.58,-10.155 71.8,71.8 0 0 1 7.37,-7.925 q 3.525,-3.207 6.41,-5.624 l 22.35,81.7 a 32.461,32.461 0 0 1 -6.36,9.992 19.884,19.884 0 0 1 -9.41,5.938 q -11.18,3.063 -18.755,-4.643 z m -5.08,-279.9 q 3.06,-9.494 -0.94,-24.092 -4.56,-16.678 -11.97,-23.11 -7.41,-6.432 -20.88,-2.742 a 26.652,26.652 0 0 0 -10.3,4.958 16.254,16.254 0 0 0 -5.16,7.931 29.491,29.491 0 0 0 -0.84,11.131 87.189,87.189 0 0 0 2.82,14.51 q 4.215,15.354 11.07,21.728 6.87,6.374 19.68,2.867 13.465,-3.686 16.515,-13.181 z m -71.87,19.668 q 2.97,-9.472 -1.02,-24.069 -4.575,-16.68 -11.9,-23.133 -7.325,-6.453 -20.8,-2.765 a 27.308,27.308 0 0 0 -10.38,4.98 16.259,16.259 0 0 0 -5.24,7.955 29.487,29.487 0 0 0 -0.84,11.13 86.253,86.253 0 0 0 2.83,14.51 q 4.2,15.354 11.14,21.706 6.94,6.352 19.77,2.844 13.465,-3.686 16.435,-13.158 z M 1480.48,912.37 a 47.58,47.58 0 0 0 11.8,18.564 45.4,45.4 0 0 0 17.89,10.306 78.408,78.408 0 0 0 22.1,3.395 67.4,67.4 0 0 0 25.53,-4.118 51.893,51.893 0 0 0 19.02,-12.476 54.023,54.023 0 0 0 11.89,-19.763 86.733,86.733 0 0 0 1.62,-48.623 121.75,121.75 0 0 0 -7.18,-20.064 150.694,150.694 0 0 0 -9.1,-16.851 q -4.815,-7.639 -8.48,-13.008 l -33.67,-47.115 a 136.59,136.59 0 0 1 -10.11,-17.653 39.407,39.407 0 0 1 -3.64,-17.551 37.627,37.627 0 0 1 1.07,-8.435 21.217,21.217 0 0 1 3.35,-7.416 17.408,17.408 0 0 1 6.13,-5.309 19.23,19.23 0 0 1 9.4,-1.916 q 6.465,0.1 10.42,3.506 3.955,3.406 6.15,10.023 a 69.032,69.032 0 0 1 2.88,16.655 q 0.705,10.035 0.66,23.4 l 29.8,0.47 q 1.455,-6.265 3.05,-15.087 a 112.855,112.855 0 0 0 1.74,-18.252 70.1,70.1 0 0 0 -3.54,-24.527 45.556,45.556 0 0 0 -28.33,-28.653 70.055,70.055 0 0 0 -22.94,-3.9 64.538,64.538 0 0 0 -22.03,3.387 50.752,50.752 0 0 0 -18.49,11.109 55,55 0 0 0 -12.9,19.059 q -4.875,11.523 -5.12,27.241 a 92.619,92.619 0 0 0 2.29,22.443 122.454,122.454 0 0 0 6.66,20.449 155.19,155.19 0 0 0 9.75,19.024 q 5.565,9.227 11.56,18.166 l 30.83,43.336 q 3.33,4.968 5.99,9.136 a 64.23,64.23 0 0 1 4.47,8.228 47.483,47.483 0 0 1 2.77,8 32.951,32.951 0 0 1 0.89,8.27 24.629,24.629 0 0 1 -4.66,14.48 q -4.53,6.222 -14.23,6.066 a 25.158,25.158 0 0 1 -11.8,-2.741 18.184,18.184 0 0 1 -7.62,-8.572 q -2.8,-5.942 -3.92,-15.885 a 198.739,198.739 0 0 1 -0.89,-24.682 L 1481.23,854 q -1.44,4.893 -3.02,13.122 a 99.7,99.7 0 0 0 -1.72,17.073 q -0.255,16.705 3.99,28.175 z"
         inkscape:connector-curvature="0"
         style="fill:white;fill-rule:evenodd"
         inkscape:label="iknas_road_as_shape" />
      <path
         id="S"
         class="cls-1"
         d="M 661,849 C 618.416,814.218 620.075,800.549 617.744,760.319 615.59,723.194 642.626,732.35 667,703 c 18.962,-22.823 48.112,-24.326 77,-26 28.888,-1.674 35.529,7.521 57,28 30.667,29.274 28.895,30.868 58,44 l 65,-67 c -38.59,-77.882 -38.651,-37.471 -77,-77 -34.715,-35.784 -47.193,-56.336 -63,-50 -48.34,19.375 -107.174,46.143 -209,84 -61.446,23.022 -50.847,54.11 -44,122 6.832,67.906 -20.549,110.465 28,148 66.762,52.005 134.961,19.438 183,95 43.438,68.71 28.032,64.69 48,104 28.705,56.52 0.026,38.78 -27,92 -15.369,30.25 -23.8,87.32 -70,90 -34.661,2.01 -39.567,3.98 -75,-19 -36.04,-23.34 -47.371,-22.43 -99,-37 l -91,21 c -22.616,10.91 6.105,69.9 24,73 l 71,10 c 56.732,29.98 29.707,0.36 78.795,47.18 39.863,38.05 126.483,9.23 192.205,-13.18 58.945,-20.1 56.281,-70.5 84,-123 30.019,-56.87 18.439,-33.54 17,-111 -1.831,-98.56 -22.859,-168.984 -81,-208 -58.967,-39.979 -65.008,-5 -128.884,-57.172 z"
         inkscape:connector-curvature="0"
         style="fill:white;fill-rule:evenodd" />
      </clipPath>
  </defs>
  <g
     id="g4553"
     inkscape:label="Logo"
     clip-path="url(#clipPath4562)">
    <rect
       inkscape:label="Background"
       y="0"
       x="0"
       height="2151.8179"
       width="2161.4312"
       id="rect3713"
       style="opacity:1;fill:#57744a;fill-opacity:1;fill-rule:nonzero;stroke:#000000;stroke-width:7.55905533;stroke-miterlimit:4;stroke-dasharray:none;stroke-opacity:1" />
    <g
       id="Siknas"
       inkscape:label="Siknas">
      <path
         id="iknäs_road_as_shape"
         data-name="iknäs road as shape"
         class="cls-1"
         d="m 904.1,808.61 q 3.732,-10.218 -1.036,-24.787 -5.137,-15.688 -13.775,-20.719 -8.638,-5.031 -20.777,-1.055 a 32.915,32.915 0 0 0 -9.84,4.98 19.527,19.527 0 0 0 -6.038,7.56 24.406,24.406 0 0 0 -1.859,10.742 52.626,52.626 0 0 0 2.918,14.658 q 4.953,15.129 14.078,20.827 9.125,5.698 20.455,1.988 12.136,-3.975 15.874,-14.194 z m 59.183,315.12 40.952,-13.41 -84.217,-257.188 -40.954,13.41 z m 84.282,-27.85 40.19,-15.55 -48.455,-125.185 1.27,-0.492 94.52,107.357 40.98,-15.87 -106.21,-116.313 3.92,-134.282 -38.6,14.94 -0.92,127.856 -1.28,0.491 -74.268,-191.9 -40.188,15.555 z m 148.23,-59.63 40.51,-14.69 -74.62,-205.823 a 44.962,44.962 0 0 1 6.02,-16.61 q 4.335,-6.793 10.42,-9 8.64,-3.135 15.51,1.8 6.87,4.935 12.96,21.747 l 70.06,193.259 40.52,-14.683 -70.685,-194.93 q -11.31,-31.223 -27.46,-43.035 -16.15,-11.812 -35.53,-4.785 a 55.687,55.687 0 0 0 -11.71,5.92 46.331,46.331 0 0 0 -10.28,9.371 56.856,56.856 0 0 0 -8.07,13.482 74.758,74.758 0 0 0 -5.07,18.249 l -0.07,-0.185 -13.53,-25.825 -31.22,11.321 z m 222.33,-77.036 a 56.041,56.041 0 0 0 13.01,-23.121 l 9.07,21.559 30.89,-8.451 -53.485,-195.441 a 152.848,152.848 0 0 0 -10.96,-29.4 q -6.225,-12.147 -15.22,-18.859 a 41.677,41.677 0 0 0 -21.33,-7.918 q -12.345,-1.207 -29.26,3.423 a 72.8,72.8 0 0 0 -22.76,10.4 53.056,53.056 0 0 0 -15.51,16.571 53.964,53.964 0 0 0 -7.02,22.094 q -1.29,12.378 2.7,26.972 a 106.08,106.08 0 0 0 4.09,12.024 q 2.415,5.961 5.92,12.947 l 31.71,-8.676 -3.11,-11.374 a 82.293,82.293 0 0 1 -3.25,-19.284 37.625,37.625 0 0 1 1.78,-13.525 19.061,19.061 0 0 1 5.63,-8.469 21.489,21.489 0 0 1 8.1,-4.256 q 6.57,-1.8 11.1,-0.083 a 17.187,17.187 0 0 1 7.75,6.032 40.851,40.851 0 0 1 5.49,10.722 q 2.28,6.4 4.36,13.987 l 9.44,34.5 q -5.355,4.322 -12.14,10.149 -6.785,5.827 -12.05,11.142 a 160.833,160.833 0 0 0 -18.56,21.888 88.407,88.407 0 0 0 -11.51,22.817 81.212,81.212 0 0 0 -3.93,25.323 112.178,112.178 0 0 0 4.38,29.568 106.22,106.22 0 0 0 9.7,24.141 65.08,65.08 0 0 0 13.88,17.5 44.2,44.2 0 0 0 17.33,9.42 37.074,37.074 0 0 0 19.96,-0.268 49.405,49.405 0 0 0 23.8,-14.054 z m -34.26,-32.6 q -7.59,-7.7 -11.68,-22.681 a 71.891,71.891 0 0 1 -2.75,-18.1 65.4,65.4 0 0 1 1.56,-15.607 52.613,52.613 0 0 1 4.68,-12.895 64.545,64.545 0 0 1 6.58,-10.155 71.8,71.8 0 0 1 7.37,-7.925 q 3.525,-3.207 6.41,-5.624 l 22.35,81.7 a 32.461,32.461 0 0 1 -6.36,9.992 19.884,19.884 0 0 1 -9.41,5.938 q -11.18,3.063 -18.755,-4.643 z m -5.08,-279.9 q 3.06,-9.494 -0.94,-24.092 -4.56,-16.678 -11.97,-23.11 -7.41,-6.432 -20.88,-2.742 a 26.652,26.652 0 0 0 -10.3,4.958 16.254,16.254 0 0 0 -5.16,7.931 29.491,29.491 0 0 0 -0.84,11.131 87.189,87.189 0 0 0 2.82,14.51 q 4.215,15.354 11.07,21.728 6.87,6.374 19.68,2.867 13.465,-3.686 16.515,-13.181 z m -71.87,19.668 q 2.97,-9.472 -1.02,-24.069 -4.575,-16.68 -11.9,-23.133 -7.325,-6.453 -20.8,-2.765 a 27.308,27.308 0 0 0 -10.38,4.98 16.259,16.259 0 0 0 -5.24,7.955 29.487,29.487 0 0 0 -0.84,11.13 86.253,86.253 0 0 0 2.83,14.51 q 4.2,15.354 11.14,21.706 6.94,6.352 19.77,2.844 13.465,-3.686 16.435,-13.158 z M 1480.48,912.37 a 47.58,47.58 0 0 0 11.8,18.564 45.4,45.4 0 0 0 17.89,10.306 78.408,78.408 0 0 0 22.1,3.395 67.4,67.4 0 0 0 25.53,-4.118 51.893,51.893 0 0 0 19.02,-12.476 54.023,54.023 0 0 0 11.89,-19.763 86.733,86.733 0 0 0 1.62,-48.623 121.75,121.75 0 0 0 -7.18,-20.064 150.694,150.694 0 0 0 -9.1,-16.851 q -4.815,-7.639 -8.48,-13.008 l -33.67,-47.115 a 136.59,136.59 0 0 1 -10.11,-17.653 39.407,39.407 0 0 1 -3.64,-17.551 37.627,37.627 0 0 1 1.07,-8.435 21.217,21.217 0 0 1 3.35,-7.416 17.408,17.408 0 0 1 6.13,-5.309 19.23,19.23 0 0 1 9.4,-1.916 q 6.465,0.1 10.42,3.506 3.955,3.406 6.15,10.023 a 69.032,69.032 0 0 1 2.88,16.655 q 0.705,10.035 0.66,23.4 l 29.8,0.47 q 1.455,-6.265 3.05,-15.087 a 112.855,112.855 0 0 0 1.74,-18.252 70.1,70.1 0 0 0 -3.54,-24.527 45.556,45.556 0 0 0 -28.33,-28.653 70.055,70.055 0 0 0 -22.94,-3.9 64.538,64.538 0 0 0 -22.03,3.387 50.752,50.752 0 0 0 -18.49,11.109 55,55 0 0 0 -12.9,19.059 q -4.875,11.523 -5.12,27.241 a 92.619,92.619 0 0 0 2.29,22.443 122.454,122.454 0 0 0 6.66,20.449 155.19,155.19 0 0 0 9.75,19.024 q 5.565,9.227 11.56,18.166 l 30.83,43.336 q 3.33,4.968 5.99,9.136 a 64.23,64.23 0 0 1 4.47,8.228 47.483,47.483 0 0 1 2.77,8 32.951,32.951 0 0 1 0.89,8.27 24.629,24.629 0 0 1 -4.66,14.48 q -4.53,6.222 -14.23,6.066 a 25.158,25.158 0 0 1 -11.8,-2.741 18.184,18.184 0 0 1 -7.62,-8.572 q -2.8,-5.942 -3.92,-15.885 a 198.739,198.739 0 0 1 -0.89,-24.682 L 1481.23,854 q -1.44,4.893 -3.02,13.122 a 99.7,99.7 0 0 0 -1.72,17.073 q -0.255,16.705 3.99,28.175 z"
         inkscape:connector-curvature="0"
         style="fill:#35462d;fill-rule:evenodd"
         inkscape:label="iknas_road_as_shape" />
      <path
         id="S"
         class="cls-1"
         d="M 661,849 C 618.416,814.218 620.075,800.549 617.744,760.319 615.59,723.194 642.626,732.35 667,703 c 18.962,-22.823 48.112,-24.326 77,-26 28.888,-1.674 35.529,7.521 57,28 30.667,29.274 28.895,30.868 58,44 l 65,-67 c -38.59,-77.882 -38.651,-37.471 -77,-77 -34.715,-35.784 -47.193,-56.336 -63,-50 -48.34,19.375 -107.174,46.143 -209,84 -61.446,23.022 -50.847,54.11 -44,122 6.832,67.906 -20.549,110.465 28,148 66.762,52.005 134.961,19.438 183,95 43.438,68.71 28.032,64.69 48,104 28.705,56.52 0.026,38.78 -27,92 -15.369,30.25 -23.8,87.32 -70,90 -34.661,2.01 -39.567,3.98 -75,-19 -36.04,-23.34 -47.371,-22.43 -99,-37 l -91,21 c -22.616,10.91 6.105,69.9 24,73 l 71,10 c 56.732,29.98 29.707,0.36 78.795,47.18 39.863,38.05 126.483,9.23 192.205,-13.18 58.945,-20.1 56.281,-70.5 84,-123 30.019,-56.87 18.439,-33.54 17,-111 -1.831,-98.56 -22.859,-168.984 -81,-208 -58.967,-39.979 -65.008,-5 -128.884,-57.172 z"
         inkscape:connector-curvature="0"
         style="fill:#35462d;fill-rule:evenodd" />
    </g>
    <g
       id="Vatten">
      <path
         id="Bäcken"
         class="cls-2"
         d="m 786,555 c -48.34,19.375 -107.173,46.143 -209,84 -61.446,23.022 -50.847,54.11 -44,122 6.831,67.906 -20.55,110.465 28,148 66.761,52.005 134.96,19.438 183,95 43.437,68.71 28.032,64.69 48,104 28.705,56.52 0.026,38.78 -27,92 -15.37,30.25 -23.8,87.32 -70,90 -34.661,2.01 -42.855,5.42 -78,-18 -28.238,-18.79 -44.371,-21.43 -96,-36 l -94,19 c 0,0 -46.547,17.02 -59,36 -12.453,18.98 -12.209,28.95 -14,44 -3.091,25.97 -31,38 -31,38 0,0 -13.633,2.58 -6,20 7.633,17.42 35.631,131.7 51,141 15.369,9.3 15.534,6.34 34,14 18.466,7.66 40.982,3.52 56,11 15.018,7.48 22.072,23.71 17,38 -5.072,14.29 -18.834,22.63 -22,37 -3.166,14.37 -14.2,20.91 6,47 20.2,26.09 23.98,18.01 19,46 -4.98,27.99 4.709,40.02 5,54 0.291,13.98 7.162,10.39 12,40"
         inkscape:connector-curvature="0"
         style="fill:none;fill-rule:evenodd;stroke:#90a3bc;stroke-width:20px"
         inkscape:label="Backen" />
      <path
         id="Byträsket"
         class="cls-3"
         d="m 1182,-280 1407,1 c -8.29,15.235 -22.93,24.954 -28,43.022 -8.76,31.177 0.5,74.488 -24,89.045 -26,15.445 -132.77,1.7 -164,-7 h -26 c -32.42,-9.058 -75.97,-7.095 -108,-16.008 h -30 c -22.21,-6.173 -47,-14.164 -68,-20.01 -13.77,-3.832 -33.89,1.749 -42,4 -19.73,5.48 -48.55,-0.292 -64,4 h -50 c -15.47,5.129 -31.85,27.889 -43,39.02 -20,19.955 -46.51,34.7 -62,59.03 -16.13,25.337 -37.84,79 -58,97.049 Q 1706.005,85.177 1590,157.22 c -88.13,74.944 -181.71,139.769 -283,202.1 l -36,8 -76,55.028 h -22 c -31.06,8.655 -82.95,-2.448 -114,8 q -16.005,13.005 -32,26.013 c -25.53,11.289 -80.422,27 -99,43.022 q -18,29.012 -36,58.029 c -7.669,6.832 -52.461,34.89 -65,30.015 -12.29,-5.59 -15.224,-20.029 -25,-28.014 l -20,-6 c -6.932,-5.691 -6.271,-15.043 -12,-22.011 -13.282,-16.153 -28.742,-26.9 -39,-47.024 l -21,-42.021 q 1,-6 2,-12.006 l -14,-17.009 c -15.218,-13.167 -96.723,-31 -127,-31.015 v -3 c 13.186,-42.389 13.6,-49.931 62,-58.029 4.812,-7.341 1.934,-14.1 3,-23.012 l 21,-3 q 2,-3 4,-6 c -4.2,-8.776 -9.773,-23.429 -18,-28.014 -9.374,-5.225 -14.356,0.845 -20,-8 3.858,-14.669 41.443,-23.171 64,-17.009 34.613,9.456 123.268,-28.944 164,-37.018 24.445,-44.484 15.04,-79.1 60,-108.055 14.369,-9.254 35.754,-7.685 54,-13.007 50.7,-14.788 144.92,-26.629 176,-60.03 -1.66,-21.073 -22.15,-27.477 -28,-44.022 -9.93,-28.081 -16.74,-57.136 -24,-84.042 -2.89,-10.713 4.86,-17.848 6,-24.012 l -6,-18.01 c -7.44,-29.2 -9.5,-26.147 0,-54.027 3.4,-9.984 -0.15,-15.378 13,-16.008 6.14,3.184 22.86,10.338 28,7 14.89,-7.375 35.16,-19.895 46,-32.016 q -2.505,-12.505 -5,-25.013 5.505,-4.003 11,-8.003 z"
         inkscape:connector-curvature="0"
         style="fill:#90a3bc;fill-rule:evenodd"
         inkscape:label="Bytrasket" />
      <path
         id="Havet"
         class="cls-3"
         d="m 3174,1463 c 0.33,0.67 0.67,1.33 1,2 -0.33,-0.67 -0.67,-1.33 -1,-2 z m 191,295 c 0.03,-17.79 -7.03,-31.02 -5,-44 q 9,-4.005 18,-8 c 4.96,7.49 4.47,12.49 15,15 -0.98,46.17 30.01,22.74 61,34 20.84,10.95 12.49,36.25 19,62 0.67,0.33 1.33,0.67 2,1 h 5 c 4.48,-6.61 19.33,-44.56 23,-47 q 44.49,-0.495 89,-1 c 64.64,-20.17 112.92,-68.03 195,-44 17.44,5.1 27.35,-14.01 47,-8 19.4,5.93 43.71,18.16 60,29 15.09,10.05 25.19,35.88 46,39 6.89,1.03 61.34,-28.46 73,-32 9.36,-2.84 83.86,8.79 93,12 q 25.5,24.99 51,50 14.505,0.495 29,1 c 13.19,18.53 21.28,42.04 41,54 q 25.5,6.495 51,13 27.99,13.995 56,28 c 9.81,4.65 48.56,30 59,28 q 73.995,-30 148,-60 h 126 c 24.85,7.24 42.43,34.32 66,40 l 78,-21 21,-21 c 16.01,1.74 25.56,14.17 39,18 15.51,4.42 27.4,-4.05 44,-4 0.33,-3.33 0.67,-6.67 1,-10 1.71,-3.65 2.69,-4.07 6,-6 q 5.505,2.505 11,5 c 2.67,-1 5.33,-2 8,-3 q 0.495,-7.005 1,-14 c 30.61,-15.57 54.7,31.45 87,27 l 9,-18 h 1 v 2 q 0.495,162.48 1,325 H 64 v -3 q 4,-7.995 8,-16 c -7.079,-5.2 -39.948,-32.1 -42,-39 -3.272,-11.01 9.247,-50.16 12,-60 5.436,-19.42 2.359,-34.65 8,-54 q 17,-30 34,-60 23.5,-19.005 47,-38 c 12.332,-12.98 7.6,-44.28 27,-50 23.915,-7.05 52.017,2.61 76,-4 24.268,-6.69 51.688,-16.28 76,-24 0.636,5.05 0.48,4.96 4,7 1.333,0.33 2.666,0.67 4,1 17.766,-17.08 42.091,-0.82 60,4 18.454,4.97 25.526,-12.48 47,-8 15.914,3.32 29.176,9.68 49,10 -0.078,-7.47 3.985,-6.23 6,-12 l 4,-38 q 6.5,0.495 13,1 c 0.267,24.28 -3.993,40.82 -9,59 -4.3,15.63 6.1,11.3 -2,27 q 2,5.505 4,11 c 2.506,2.16 6.292,-1.11 8,2 1.773,3.23 0.941,9.74 2,12 q 6.5,-0.495 13,-1 c 0.035,-12.78 -3.988,-12.99 -5,-23 7.927,-16.3 9.768,-31.86 21,-44 30.611,-0.62 25.752,19.57 35,39 -1.973,18.6 19.055,28.02 29,26 -0.128,-14 2.4,-56.09 5,-65 8.072,-27.67 -10.009,-71.07 5,-91 6.061,-8.05 17.719,-2.67 27,-8 q 6,-7.5 12,-15 c 5.252,2 11.782,7.18 14,12 2.96,6.43 13.963,118.12 13,122 -23.887,1.27 -49.574,14.96 -53,37 q 8.5,9.495 17,19 c 12.147,5.89 31.193,7.26 38,18 q 1,6.495 2,13 c 3.064,5.32 9.213,7.44 11,15 v 23 c 3.952,18.96 10.39,36.5 17,53 13.476,-2.4 9.028,-21.46 7,-33 0.333,-0.33 0.666,-0.67 1,-1 4,-0.33 0,-2.67 4,-3 0.342,-5.42 -0.446,-6.42 -3,-9 -3,-0.67 3,-4.33 0,-5 0.042,-13.48 -3.855,-22.64 -5,-34 9.126,-6.94 13.471,-14.19 20,-24 q 18,-17.505 36,-35 15.5,-18 31,-36 -12,-25.005 -24,-50 c 5.966,-26.36 20.734,-26.31 46,-34 4.615,-1.4 12.408,-6.66 22,-4 5.687,1.58 9.1,5.61 17,4 0.645,-11.25 0.166,-15.38 6,-23 8.369,-2.31 12.523,-7.72 19,-12 12.615,1.92 50.442,14.34 62,11 17.143,-4.95 40.714,-30.14 60,-27 q 21.99,13.5 44,27 c 9.67,2.22 38.56,-10.15 47,-12 7.72,-1.7 91.84,26.44 94,30 l 9,33 c 2.16,6.4 9.95,12.2 12,17 v 19 l 7,7 c 1.07,5.4 -5.78,5.55 -7,9 -4.05,11.47 2.2,53.55 3,56 5.88,15.26 42.86,29.19 63,26 v -5 q 13.995,0.495 28,1 c 9.63,-12.7 34.82,-21.68 40,-37 v -41 c 2.9,-9.61 12.91,-24.72 19,-34 l 54,-45 c 8.27,-12.59 15.73,-56.37 26,-63 q 22.5,-8.505 45,-17 c 22.09,-8.52 46.06,-24.82 69,-32 31.88,-9.98 63.99,-17.28 94,-26 26.53,-7.71 36.92,18.95 52,24 q 14.505,-1.005 29,-2 12.495,-0.495 25,-1 c 11.18,-5.69 14.15,-31.52 21,-42 10.68,-16.36 20.32,-31.07 31,-48 16.16,-25.61 49.31,-32.07 56,-68 0.67,-0.33 1.33,-0.67 2,-1 3.67,0.33 7.33,0.67 11,1 6.29,3.04 10.09,10.34 15,15 23.03,-0.65 56.16,-17.12 79,-10 q 20.505,12 41,24 c 14.02,4.82 33.33,4.03 49,7 12.94,17.2 13.09,75.71 6,100 v 53 q -9,10.995 -18,22 v 3 c 3.41,3.6 6.81,11.59 15,10 q 12,-8.505 24,-17 51,-0.495 102,-1 c 6.01,0.65 19.52,7.44 26,9 15.07,3.63 29.3,-4.98 47,0 2.67,1.33 5.33,2.67 8,4 q 28.5,-16.005 57,-32 c 19,-5.82 29.82,9.2 47,4 54.76,-16.57 90.21,-60.77 134,-89 16.75,2.42 21.13,9.87 28,22 12.98,-2.31 42.74,-21.92 54,-19 14.23,3.69 35.41,21.4 50,19 2.33,-1.67 4.67,-3.33 7,-5 v -6 c -5.88,-4.13 -11.22,-8.62 -12,-18 2.11,-4.42 3.48,-6.89 8,-9 22.03,-9.66 50.32,-13.24 75,-18 q 7.005,-11.505 14,-23 c 2.67,0.33 5.33,0.67 8,1 6.1,4.9 6.38,14.27 15,17 q 19.5,-1.005 39,-2 c 20.12,4.91 56.76,36.62 78,9 3.47,-8.74 3.11,-11.16 10,-16 2,0.67 4,1.33 6,2 3.35,21.95 2.06,26.07 15,37 q 16.005,-7.995 32,-16 c 14.47,-4.33 23.97,9.13 41,4 11.01,-3.32 48.16,-18.54 58,-25 q 15.495,-18 31,-36 c 6.68,-4.39 15.79,-5.73 22,-10 -0.19,-10.25 2.18,-33.74 5,-40 19.17,-6.91 34.42,-18.7 58,-20 l 9,9 c 8.25,-2.02 11.25,-8.48 17,-13 q -22.995,28.5 -46,57 v 3 c 6.57,7.05 13.13,13.2 25,15 -1,2.33 -2,4.67 -3,7 l -15,6 c 1.84,21.76 9.69,29.69 4,55 -10.13,-1.67 -19.88,-4.48 -25,4 3.56,27.64 31.88,48.14 58,51 q 9.495,-9 19,-18 c 0.03,-23.9 -16.27,-30.4 -13,-51 1,-0.33 2,-0.67 3,-1 10.3,-4.04 17.87,6.4 29,8 l 18,-12 q 1.995,-9 4,-18 3.495,-4.005 7,-8 c 1.94,-6.81 -2.91,-15.32 -1,-23 12.21,-1.97 21,-14.48 30,-21 -2.73,12.21 4.76,19.94 1,34 -6.31,23.59 -13.26,59.8 2,80 11.78,15.59 42.91,14.58 53,32 q 2.505,13.995 5,28 c 1.46,5.15 6.17,11.72 3,20 -7.02,12 -28.46,9.74 -37,20 -9.57,14.45 9.46,27.18 16,33 22.08,0.19 34.32,-7.38 54,-8 z m -3635,326 c 2,0.33 4,0.67 6,1 14.5,6.38 33.381,30.36 41,44 -2.55,10.12 -7.922,36.48 3,42 20.211,7.95 46.161,7.19 52,29 h -182 v -3 q 3.5,-16.5 7,-33 c 11.1,-6.96 43.389,-20.33 51,-28 q 11,-25.995 22,-52 z"
         inkscape:connector-curvature="0"
         style="fill:#90a3bc;fill-rule:evenodd" />
    </g>
    <g
       id="g3710"
       inkscape:label="Logo och vatten" />
    <g
       style="opacity:0.07999998;mix-blend-mode:difference"
       class="cls-4"
       id="Vägar"
       inkscape:label="Vagar">
      <path
         style="fill:none;fill-rule:evenodd;stroke:#296d69;stroke-width:20px"
         inkscape:connector-curvature="0"
         d="m 125,526 348,484 c 0,0 84.6,133.59 232,134 147.4,0.41 284.855,-12.61 295,-15 10.145,-2.39 327.68,-126.62 389,-137 61.32,-10.38 100.42,-27.251 189,-15 88.58,12.251 122.29,11.267 267,55 144.71,43.733 241.21,75.94 310,84"
         class="cls-5"
         id="Siknäsvägen"
         inkscape:label="Siknasvagen" />
      <path
         style="fill:none;fill-rule:evenodd;stroke:#296d69;stroke-width:20px"
         inkscape:connector-curvature="0"
         d="m 1018,1327 c 0,0 -4.61,86.33 95,46 99.61,-40.33 86.82,-32.39 181,-31 94.18,1.39 241.46,-44.96 267,-62 25.54,-17.04 68.93,-103.05 131,-52"
         class="cls-5"
         id="Ateljen" />
      <path
         style="fill:none;fill-rule:evenodd;stroke:#296d69;stroke-width:20px"
         inkscape:connector-curvature="0"
         id="path18"
         d="M 2383,1646"
         class="cls-5" />
      <path
         style="fill:none;fill-rule:evenodd;stroke:#296d69;stroke-width:20px"
         inkscape:connector-curvature="0"
         d="m 630,1486 c 0,0 40.037,134.05 44,179 3.963,44.95 22,226 22,226"
         class="cls-5"
         id="Hamnen" />
      <path
         style="fill:none;fill-rule:evenodd;stroke:#296d69;stroke-width:20px"
         inkscape:connector-curvature="0"
         d="m 230,1406 c 0,0 -33.594,-37.01 -138,11 -104.406,48.01 -62,23 -62,23"
         class="cls-5"
         id="Viken" />
      <path
         style="fill:none;fill-rule:evenodd;stroke:#296d69;stroke-width:20px"
         inkscape:connector-curvature="0"
         d="m 559,1103 c 0,0 -183.833,125.62 -223,177 -39.167,51.38 -149.638,165.57 -162,239 -12.362,73.43 6.88,89.52 33,111 26.12,21.48 73.288,52.09 196,-13 122.712,-65.09 282.307,-194.32 374,-216 83.4,-19.72 263.28,-36.47 245,-146 -18.45,-110.53 -23,-121 -23,-121"
         class="cls-5"
         data-name="Runt byn"
         id="Runt_byn" />
      <path
         style="fill:none;fill-rule:evenodd;stroke:#296d69;stroke-width:20px"
         inkscape:connector-curvature="0"
         d="m 2135,133 -638,450 c 0,0 -125.27,105.348 -148,181 -31.24,103.975 -31.35,168.034 -13,256"
         class="cls-5"
         id="Lappkullen" />
    </g>
  </g>
  <circle
     id="circle4528"
     r="1069.5"
     cy="1069.5"
     cx="1069.5"
     style="display:none"
     inkscape:label="Cirkel" />
</svg>
`

func main() {
	fmt.Println(svgData)

	fmt.Println("---------------------------------")
		
	doc := xmldom.Must(xmldom.ParseXML(svgData))
	fmt.Println(doc.XMLPretty())
}
@JoakimSoderberg
Copy link
Author

Prefix was not the correct term

Seems like the reason is this code:

go-xmldom/dom.go

Lines 50 to 55 in e1029cd

for _, attr := range token.Attr {
el.Attributes = append(el.Attributes, &Attribute{
Name: attr.Name.Local,
Value: attr.Value,
})
}

More specifically this line:

Name: attr.Name.Local,

You are only using the Local and just dropping the Space part.

https://golang.org/pkg/encoding/xml/#Name

A Name represents an XML name (Local) annotated with a name space identifier (Space). In tokens returned by Decoder.Token, the Space identifier is given as a canonical URL, not the short prefix used in the document being parsed.

type Name struct {
       Space, Local string
}

@JoakimSoderberg
Copy link
Author

Ok, so simply adding Space does not help. Since that apparently is always a full url. Which equally breaks things:

<http://www.w3.org/2000/svg:svg xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:cc="http://creativecommons.org/ns#" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:svg="http://www.w3.org/2000/svg" xmlns="http://www.w3.org/2000/svg" xmlns:sodipodi="http://sodipodi.sourceforge.net/DTD/sodipodi-0.dtd" xmlns:inkscape="http://www.inkscape.org/namespaces/inkscape" id="Logo" width="2139" height="2139" viewBox="0 0 2139 2139" version="1.1" http://sodipodi.sourceforge.net/DTD/sodipodi-0.dtd:docname="siknas07-alt03.svg" http://www.inkscape.org/namespaces/inkscape:version="0.92.1 r15371" http://www.inkscape.org/namespaces/inkscape:label="Cirkel">
This page contains the following errors:
error on line 2 at column 7: Failed to parse QName 'http:'
Below is a rendering of the page up to the first error.

Not sure if this is just something inherent in the golang API when parsing XML, or if it's controllable.

What happens is that this is read:

xmlns:inkscape="http://www.inkscape.org/namespaces/inkscape"

As well as these attributes from the original:

inkscape:version="0.92.1 r15371"
inkscape:label="Cirkel"

When parsing this, the fully expanded Space is saved. So instead of Space being inkscape for version it is the full URL http://www.inkscape.org/namespaces/inkscape. Which is what Chrome fails on.

@JoakimSoderberg
Copy link
Author

Seems like this is just how it works:

https://golang.org/pkg/encoding/xml/#Decoder.Token

Token implements XML name spaces as described by http://www.w3.org/TR/REC-xml-names/. Each of the Name structures contained in the Token has the Space set to the URL identifying its name space when known. If Token encounters an unrecognized name space prefix, it uses the prefix as the Space rather than report an error.

I see it was also mentioned in https://golang.org/pkg/encoding/xml/#Name

A Name represents an XML name (Local) annotated with a name space identifier (Space). In tokens returned by Decoder. Token, the Space identifier is given as a canonical URL, not the short prefix used in the document being parsed.

But then I don't get why chrome thinks it's an invalid XML file. The wonderful world of overly complex standards 🤕

@JoakimSoderberg
Copy link
Author

Ok, so the marshalling implementation does this properly. The used the expanded Space and reverse the process when writing the XML:
https://github.com/golang/go/blob/165ebe65585ec7ae63695fab9e7aabaaad1af57c/src/encoding/xml/marshal.go#L700-L715

https://github.com/golang/go/blob/165ebe65585ec7ae63695fab9e7aabaaad1af57c/src/encoding/xml/marshal.go#L314-L316

That is, instead of simply outputting:

http://www.inkscape.org/namespaces/inkscape:version="0.92.1 r15371"

it first creates:

xlmns:inkscape="http://www.inkscape.org/namespaces/inkscape"

And then uses it properly:

inkscape:version="0.92.1 r15371"

So instead of using your own Attribute struct here:

go-xmldom/node.go

Lines 14 to 17 in e1029cd

type Attribute struct {
Name string
Value string
}

You should use the encoder/xml Name one that keeps the Space in the name:

type Name struct {
       Space, Local string
}

Or something similar to that.

Unfortunately that breaks backwards compatability

So the correct way to do this is to keep the Space, so it can be used when Marshaling.


Sorry for the spamming

@subchen
Copy link
Owner

subchen commented Mar 28, 2018

Because I cannot find a best way to support xpath for namespace, so I drop the namespace for implementation.

I am trying to add full support for namespace in new branch namespace.

@mantyr
Copy link

mantyr commented Oct 27, 2019

mantyr@6bd17e5

added namespaces prefix

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants