flofloflorian
flofloflorian

Reputation: 13

Escaping "<" in JavaScript part of SVG file

I'm having an issue with using the "<" character in the JavaScript part of my dynamic SVG file.
Opening the file in browser gives me a not well-formed error pointing at the next character.

I realised that I will probably have to escape this character, but I don't know how.
Using $lt as recommended for escaping < in XML didn't work.

Here is a little code snippet showing the issue:

<svg width="100%" height="100%" version="1.1" xmlns="http://www.w3.org/2000/svg">

  <script>

    for (it=0;it<5;it++) {
      
    }

  <script>

</svg>

Upvotes: 1

Views: 422

Answers (1)

Dave Newton
Dave Newton

Reputation: 160181

All of the JS content (e.g., everything after <script> should be wrapped in <![CDATA[.

E.g.,

<svg ...>
  <script><![CDATA[
    ...JS...
  ]]>
  </script>
  ...
</svg>

Normal XML stuff.

Upvotes: 1

Related Questions