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

2

11

I'm building an SVG document which contains various image tags. The xlink:href (source URL) attributes for the images contain query strings with ampersands. If I escape them as %26 or the ascii encoding ? they're not valid query strings and the server won't deliver the image. I can't escape them with CDATA because they're attributes (not nodes). I've tried creating an xlink:href node within the image tag but that get's ignored by the SVG parser. I want to use pure SVG (not SVG within HTML) so that I can convert to a JPG later, thus scripting is out...

Any hints on how I can make the 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!

Rachelrachele answered 2/8, 2011 at 16:7 Comment(1)
Oops! The solution is to replace the ampersands with the correct ascii code #38 and Not #63 (which is a question mark '?') as I had initially tried after mis-reading this question: https://mcmap.net/q/1019463/-using-quot-quot-in-svg-href Ascii codes: ascii.cl/htmlcodes.htm Thanks to Stunti stackoverflow.com/users/54949/stuntiRachelrachele
R
4

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

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

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

Rachelrachele answered 3/8, 2011 at 8:35 Comment(0)
S
5

In all XML applications, including SVG, the following entities are valid without a custom DTD:

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

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

<image xlink:href="http://foo.com/bar.jpg?token=asdf&amp;exp=9384&amp;etc=etc"/>
Shorthand answered 2/8, 2011 at 22:3 Comment(1)
Unfortunately, &amp; didn't work because the browser didn't translate them back into actual ampersands at render-time and thus, the query strings didn't work... Thanks, all the same.Rachelrachele
R
4

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

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

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

Rachelrachele answered 3/8, 2011 at 8:35 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.