I’m trying to write correct svg from string which uses special characters.I’m using UTF-8 encoding for svg document.I’m working on javascript .
The string is like :
<glyph unicode="¥" horiz-adv-x="819" />
While writing xml using DOMParser api , it converts ¥ into ¥ which is incorrect xml and browser throws XML Parsing error .
Here is the complete text which I want to convert into SVG document .
<?xml version="1.0" standalone="no"?>
<!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN" "http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd" >
<svg xmlns="http://www.w3.org/2000/svg">
<metadata></metadata>
<defs>
<font id="DearestRegular" horiz-adv-x="2048" >
<font-face units-per-em="2048" ascent="1638" descent="-410" />
<glyph unicode="¥" horiz-adv-x="819" />
</font>
</defs>
</svg>
Using DOMParser I’m getting the output like :
<?xml version="1.0" standalone="no"?>
<!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN" "http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd" >
<svg xmlns="http://www.w3.org/2000/svg">
<metadata></metadata>
<defs>
<font id="DearestRegular" horiz-adv-x="2048" >
<font-face units-per-em="2048" ascent="1638" descent="-410" />
<glyph unicode="¥" horiz-adv-x="819" />
</font>
</defs>
</svg>
This throws XML Parsing error in browser .
That is not incorrect XML.
Possibly your server is sending the wrong character encoding information in the HTTP headers.
(Since the XML declaration doesn’t say otherwise, you should be using UTF-8)