Ampersands (&) in xlink: href attributes of SVG images?

I am creating an SVG document that contains various image tags. The xlink: href (source URL) attributes for images contain query strings with ampersands. If I run them off as% 26 or encoding ascii & # 63; they are not valid query strings, and the server will not provide an image. I cannot avoid them with CDATA because they are attributes (not nodes). I tried to create an xlink: href node inside an image tag, but ignored the SVG parser. I want to use pure SVG (not SVG in HTML), so that I can later convert to JPG, so the scripts do not work ...

Any tips on how I can do below work?

<image x="0" y="0" width="306" height="306" xlink:href="http://host.com/image.jpg?token=asdf&expiration=9384029&etc=etc"/> 

Thanks!

+6
source share
2 answers

The solution is to replace the ampersands with the correct ascii # 38 and Not # 63 code (which is the question mark '?'), As I initially tried after reading this question incorrectly: using "" "in SVG href

Thanks to Stunti https://stackoverflow.com/users/54949/stunti

http://www.ascii.cl/htmlcodes.htm

+2
source

In all XML applications, including SVG, the following objects are allowed without a special DTD:

  • &amp; - &
  • &gt;
  • &lt; - <

In your case, this should work without resorting to the ugly ASCII hacks:

 <image xlink:href="http://foo.com/bar.jpg?token=asdf&amp;exp=9384&amp;etc=etc"/> 
+1
source

Source: https://habr.com/ru/post/894122/


All Articles