hipchat / x2js

This library provides XML to JSON (JavaScript Objects) and vice versa javascript conversion functions. The library is very small and doesn't require any other additional libraries. Forked from https://code.google.com/p/x2js/
0 stars 2 forks source link

/ is escaped but should NOT be escaped #36

Open GoogleCodeExporter opened 9 years ago

GoogleCodeExporter commented 9 years ago
This results in xml-files that looks ugly like this:

...
    xmlns:xsd="http://www.w3.org/2001/XMLSchema"
...

The only characters that has to be escaped are: <, &, >, ", '
Also ' should be replaced with &apos;
See: 
http://en.wikipedia.org/wiki/List_of_XML_and_HTML_character_entity_references#En
tities_representing_special_characters_in_XHTML

Replacement code:

    function escapeXmlChars(str) {
        if(typeof(str) == "string")
            return str.replace(/&/g, '&amp;').replace(/</g, '&lt;').replace(/>/g, '&gt;').replace(/"/g, '&quot;').replace(/'/g, '&apos;');
        else
            return str;
    }

Also the unescapeXmlChars should handle any escaped character (unicode and 
named) and not a small predefined set.

Original issue reported on code.google.com by david.gr...@gmail.com on 5 Feb 2015 at 1:34