<html xmlns:v="urn:schemas-microsoft-com:vml" xmlns:o="urn:schemas-microsoft-com:office:office" xmlns:w="urn:schemas-microsoft-com:office:word" xmlns:m="http://schemas.microsoft.com/office/2004/12/omml" xmlns="http://www.w3.org/TR/REC-html40"><head><meta http-equiv=Content-Type content="text/html; charset=utf-8"><meta name=Generator content="Microsoft Word 14 (filtered medium)"><style><!--
/* Font Definitions */
@font-face
        {font-family:Calibri;
        panose-1:2 15 5 2 2 2 4 3 2 4;}
@font-face
        {font-family:Tahoma;
        panose-1:2 11 6 4 3 5 4 4 2 4;}
@font-face
        {font-family:Menlo;
        panose-1:0 0 0 0 0 0 0 0 0 0;}
/* Style Definitions */
p.MsoNormal, li.MsoNormal, div.MsoNormal
        {margin:0cm;
        margin-bottom:.0001pt;
        font-size:12.0pt;
        font-family:"Times New Roman","serif";}
a:link, span.MsoHyperlink
        {mso-style-priority:99;
        color:blue;
        text-decoration:underline;}
a:visited, span.MsoHyperlinkFollowed
        {mso-style-priority:99;
        color:purple;
        text-decoration:underline;}
span.apple-tab-span
        {mso-style-name:apple-tab-span;}
span.EmailStyle18
        {mso-style-type:personal-reply;
        font-family:"Calibri","sans-serif";
        color:#1F497D;}
.MsoChpDefault
        {mso-style-type:export-only;
        font-size:10.0pt;}
@page WordSection1
        {size:612.0pt 792.0pt;
        margin:72.0pt 72.0pt 72.0pt 72.0pt;}
div.WordSection1
        {page:WordSection1;}
--></style><!--[if gte mso 9]><xml>
<o:shapedefaults v:ext="edit" spidmax="1026" />
</xml><![endif]--><!--[if gte mso 9]><xml>
<o:shapelayout v:ext="edit">
<o:idmap v:ext="edit" data="1" />
</o:shapelayout></xml><![endif]--></head><body lang=EN-GB link=blue vlink=purple><div class=WordSection1><p class=MsoNormal><span style='font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D'>Hi John,<o:p></o:p></span></p><p class=MsoNormal><span style='font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D'><o:p> </o:p></span></p><p class=MsoNormal><span style='font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D'>JSON has makes no distinction between different types of text, as can be the case with XML. JSON clearly specifies that escaping is limited to a small character set. These are listed in JSON specifications, e.g. ECMA404 (<a href="http://www.ecma-international.org/publications/files/ECMA-ST/ECMA-404.pdf">http://www.ecma-international.org/publications/files/ECMA-ST/ECMA-404.pdf</a>). So, of relevance here is \” to represent the double quotation mark, \\ to represent the reverse solidus character, and \n to represent the line feed character. Note that the single quotation mark ‘ is never escaped. Therefore the escape sequence \’ is invalid JSON.<o:p></o:p></span></p><p class=MsoNormal><span style='font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D'><o:p> </o:p></span></p><p class=MsoNormal><span style='font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D'>Now, what about XML.<o:p></o:p></span></p><p class=MsoNormal><span style='font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D'><o:p> </o:p></span></p><p class=MsoNormal><span style='font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D'>Let’s take as an example line 85 in the example file  CreateX3DFromStringRandomSpheres.x3d, where the line is:<o:p></o:p></span></p><p class=MsoNormal><span style='font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D'><o:p> </o:p></span></p><p class=MsoNormal style='text-autospace:none'><span style='font-size:10.0pt;font-family:"Arial","sans-serif";color:black;background:white;mso-highlight:white'>    sceneString =    '<X3D version="3.1" profile="Interchange">\n' +<o:p></o:p></span></p><p class=MsoNormal><span style='font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D'><o:p> </o:p></span></p><p class=MsoNormal><span style='font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D'>Since this is part of a CDATA section, the only escaped character in this line is the \n line feed character.<o:p></o:p></span></p><p class=MsoNormal><span style='font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D'><o:p> </o:p></span></p><p class=MsoNormal><span style='font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D'>On translating it to JSON, we note that the double quotation marks will both need escaping, as will the line feed character. The single quotation mark must not be escaped. So, how does this line get translated by the stylesheet? In the JSON it is line 278:<o:p></o:p></span></p><p class=MsoNormal><span style='font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D'><o:p> </o:p></span></p><p class=MsoNormal style='text-autospace:none'><span style='font-size:10.0pt;font-family:"Arial","sans-serif";color:maroon;background:white;mso-highlight:white'>"    sceneString =    '<X3D version=\"3.1\" profile=\"Interchange\">\\' +"</span><span style='font-size:10.0pt;font-family:"Arial","sans-serif";color:blue;background:white;mso-highlight:white'>,</span><span style='font-size:10.0pt;font-family:"Arial","sans-serif";color:black;background:white;mso-highlight:white'><o:p></o:p></span></p><p class=MsoNormal><span style='font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D'><o:p> </o:p></span></p><p class=MsoNormal><span style='font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D'>We note that, as expected, both double quotation marks are escaped. The single quotation marks, as expected, are not escaped. However, the line feed is incorrect. Instead, we simply have an escaped reverse solidus character. This is incorrect. The line should be<o:p></o:p></span></p><p class=MsoNormal><span style='font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D'><o:p> </o:p></span></p><p class=MsoNormal style='text-autospace:none'><span style='font-size:10.0pt;font-family:"Arial","sans-serif";color:maroon;background:white;mso-highlight:white'>"    sceneString =    '<X3D version=\"3.1\" profile=\"Interchange\">\n' +"</span><span style='font-size:10.0pt;font-family:"Arial","sans-serif";color:blue;background:white;mso-highlight:white'>,</span><span style='font-size:10.0pt;font-family:"Arial","sans-serif";color:black;background:white;mso-highlight:white'><o:p></o:p></span></p><p class=MsoNormal><span style='font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D'><o:p> </o:p></span></p><p class=MsoNormal><span style='font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D'>So there is a problem with the stylesheet.<o:p></o:p></span></p><p class=MsoNormal><span style='font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D'><o:p> </o:p></span></p><p class=MsoNormal><span style='font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D'>Now, what about a converter reading this file in and translating it back to XML?<o:p></o:p></span></p><p class=MsoNormal><span style='font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D'><o:p> </o:p></span></p><p class=MsoNormal><span style='font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D'>The reader should recognise that the whole #sourceText array, starting at line 257, is an array of strings that will be converted back to a single unquoted CDATA section. Each individual string in the JSON is enclosed in double quotation marks. These are being removed on converting back to XML. So the \” escape sequences in JSON are not required to be escaped in XML. Thus the conversion back should, assuming that the corrected JSON was used, would successfully round trip back to the original XML quoted above.<o:p></o:p></span></p><p class=MsoNormal><span style='font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D'><o:p> </o:p></span></p><p class=MsoNormal><span style='font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D'>Regards,<o:p></o:p></span></p><p class=MsoNormal><span style='font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D'><o:p> </o:p></span></p><p class=MsoNormal><span style='font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D'>Roy<o:p></o:p></span></p><p class=MsoNormal><span style='font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D'><o:p> </o:p></span></p><p class=MsoNormal><span style='font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D'><o:p> </o:p></span></p><div><div style='border:none;border-top:solid #B5C4DF 1.0pt;padding:3.0pt 0cm 0cm 0cm'><p class=MsoNormal><b><span lang=EN-US style='font-size:10.0pt;font-family:"Tahoma","sans-serif"'>From:</span></b><span lang=EN-US style='font-size:10.0pt;font-family:"Tahoma","sans-serif"'> John Carlson [mailto:yottzumm@gmail.com] <br><b>Sent:</b> 18 April 2016 02:32<br><b>To:</b> Don Brutzman; Roy Walmsley<br><b>Cc:</b> X3D Graphics public mailing list<br><b>Subject:</b> Re: X3dToJson.xslt error. \n converted to \\ in script<o:p></o:p></span></p></div></div><p class=MsoNormal><o:p> </o:p></p><p class=MsoNormal>Also compare quoting in scripts for these two files:<o:p></o:p></p><div><p class=MsoNormal><o:p> </o:p></p></div><div><div><p class=MsoNormal><span style='font-size:8.5pt;font-family:"Menlo","serif"'>/<a href="http://www.web3d.org/x3d/content/examples/Basic/development/CameraPrototypes.json">www.web3d.org/x3d/content/examples//Basic/development/CameraPrototypes.json</a> <o:p></o:p></span></p></div><div><p class=MsoNormal><span style='font-size:8.5pt;font-family:"Menlo","serif"'><br><br><o:p></o:p></span></p></div><div><p class=MsoNormal><span style='font-size:8.5pt;font-family:"Menlo","serif"'>/<a href="http://www.web3d.org/x3d/content/examples/Basic/development/CameraPrototypes.x3d">www.web3d.org/x3d/content/examples//Basic/development/CameraPrototypes.x3d</a> <o:p></o:p></span></p></div><div><p class=MsoNormal><span style='font-size:8.5pt;font-family:"Menlo","serif"'><br><br><o:p></o:p></span></p></div><div><p class=MsoNormal><span style='font-size:8.5pt;font-family:"Menlo","serif"'><br><br><o:p></o:p></span></p></div><div><p class=MsoNormal><span style='font-size:8.5pt;font-family:"Menlo","serif"'>\’ gets translated to \\ (left out the ‘)<o:p></o:p></span></p></div><div><p class=MsoNormal><span style='font-size:8.5pt;font-family:"Menlo","serif"'><br><br><o:p></o:p></span></p></div><div><p class=MsoNormal><span style='font-size:8.5pt;font-family:"Menlo","serif"'>Probably below, \n should be translated to <a href="smb://n">\\n</a> or just left as is, I am not sure, something we could try.<o:p></o:p></span></p></div><div><p class=MsoNormal><span style='font-size:8.5pt;font-family:"Menlo","serif"'><br><br><o:p></o:p></span></p></div><div><p class=MsoNormal><span style='font-size:8.5pt;font-family:"Menlo","serif"'>there may be others.<o:p></o:p></span></p></div><div><p class=MsoNormal><span style='font-size:8.5pt;font-family:"Menlo","serif"'><br><br><o:p></o:p></span></p></div><div><p class=MsoNormal><span style='font-size:8.5pt;font-family:"Menlo","serif"'>Perhaps we need to write down all the initial states (in comment, in script, in shader, in url, etc) and all the transformations we need to do.<o:p></o:p></span></p></div><div><p class=MsoNormal><span style='font-size:8.5pt;font-family:"Menlo","serif"'><o:p> </o:p></span></p></div><div><p class=MsoNormal><span style='font-size:8.5pt;font-family:"Menlo","serif"'>I am just running X3dToJson.xslt with saxon.jar.  If there’s any more processing I need to do, let me know.<o:p></o:p></span></p></div><div><p class=MsoNormal><span style='font-size:8.5pt;font-family:"Menlo","serif"'><br><br><o:p></o:p></span></p></div><div><p class=MsoNormal><span style='font-size:8.5pt;font-family:"Menlo","serif"'>I include Java source code below for debugging.  Source code for roundtripping is here: <a href="https://github.com/coderextreme/x3droundtrip">https://github.com/coderextreme/x3droundtrip</a>  Bug reports/Issues are welcome.<o:p></o:p></span></p></div></div><div><p class=MsoNormal><span style='font-size:8.5pt;font-family:"Menlo","serif"'><o:p> </o:p></span></p></div><div><p class=MsoNormal><span style='font-size:8.5pt;font-family:"Menlo","serif"'><o:p> </o:p></span></p></div><div><p class=MsoNormal><span style='font-size:8.5pt;font-family:"Menlo","serif"'>class RunSaxon {<o:p></o:p></span></p><p class=MsoNormal><span style='font-size:8.5pt;font-family:"Menlo","serif"'>protected static class ExitException extends SecurityException <o:p></o:p></span></p><p class=MsoNormal><span style='font-size:8.5pt;font-family:"Menlo","serif"'>    {<o:p></o:p></span></p><p class=MsoNormal><span style='font-size:8.5pt;font-family:"Menlo","serif"'>        public final int status;<o:p></o:p></span></p><p class=MsoNormal><span style='font-size:8.5pt;font-family:"Menlo","serif"'>        public ExitException(int status) <o:p></o:p></span></p><p class=MsoNormal><span style='font-size:8.5pt;font-family:"Menlo","serif"'>        {<o:p></o:p></span></p><p class=MsoNormal><span style='font-size:8.5pt;font-family:"Menlo","serif"'>            super("There is no escape!");<o:p></o:p></span></p><p class=MsoNormal><span style='font-size:8.5pt;font-family:"Menlo","serif"'>            this.status = status;<o:p></o:p></span></p><p class=MsoNormal><span style='font-size:8.5pt;font-family:"Menlo","serif"'>        }<o:p></o:p></span></p><p class=MsoNormal><span style='font-size:8.5pt;font-family:"Menlo","serif"'>    }<o:p></o:p></span></p><p class=MsoNormal style='min-height: 13px'><span style='font-size:8.5pt;font-family:"Menlo","serif"'><o:p> </o:p></span></p><p class=MsoNormal><span style='font-size:8.5pt;font-family:"Menlo","serif"'>    private static class NoExitSecurityManager extends SecurityManager <o:p></o:p></span></p><p class=MsoNormal><span style='font-size:8.5pt;font-family:"Menlo","serif"'>    {<o:p></o:p></span></p><p class=MsoNormal><span style='font-size:8.5pt;font-family:"Menlo","serif"'>        @Override<o:p></o:p></span></p><p class=MsoNormal><span style='font-size:8.5pt;font-family:"Menlo","serif"'>        public void checkPermission(java.security.Permission perm) <o:p></o:p></span></p><p class=MsoNormal><span style='font-size:8.5pt;font-family:"Menlo","serif"'>        {<o:p></o:p></span></p><p class=MsoNormal><span style='font-size:8.5pt;font-family:"Menlo","serif"'>            // allow anything.<o:p></o:p></span></p><p class=MsoNormal><span style='font-size:8.5pt;font-family:"Menlo","serif"'>        }<o:p></o:p></span></p><p class=MsoNormal><span style='font-size:8.5pt;font-family:"Menlo","serif"'>        @Override<o:p></o:p></span></p><p class=MsoNormal><span style='font-size:8.5pt;font-family:"Menlo","serif"'>        public void checkPermission(java.security.Permission perm, Object context) <o:p></o:p></span></p><p class=MsoNormal><span style='font-size:8.5pt;font-family:"Menlo","serif"'>        {<o:p></o:p></span></p><p class=MsoNormal><span style='font-size:8.5pt;font-family:"Menlo","serif"'>            // allow anything.<o:p></o:p></span></p><p class=MsoNormal><span style='font-size:8.5pt;font-family:"Menlo","serif"'>        }<o:p></o:p></span></p><p class=MsoNormal><span style='font-size:8.5pt;font-family:"Menlo","serif"'>        @Override<o:p></o:p></span></p><p class=MsoNormal><span style='font-size:8.5pt;font-family:"Menlo","serif"'>        public void checkExit(int status) <o:p></o:p></span></p><p class=MsoNormal><span style='font-size:8.5pt;font-family:"Menlo","serif"'>        {<o:p></o:p></span></p><p class=MsoNormal><span style='font-size:8.5pt;font-family:"Menlo","serif"'>            super.checkExit(status);<o:p></o:p></span></p><p class=MsoNormal><span style='font-size:8.5pt;font-family:"Menlo","serif"'>            throw new ExitException(status);<o:p></o:p></span></p><p class=MsoNormal><span style='font-size:8.5pt;font-family:"Menlo","serif"'>        }<o:p></o:p></span></p><p class=MsoNormal><span style='font-size:8.5pt;font-family:"Menlo","serif"'>    }<o:p></o:p></span></p><p class=MsoNormal style='min-height: 13px'><span style='font-size:8.5pt;font-family:"Menlo","serif"'><o:p> </o:p></span></p><p class=MsoNormal><span class=apple-tab-span><span style='font-size:8.5pt;font-family:"Menlo","serif"'>                </span></span><span style='font-size:8.5pt;font-family:"Menlo","serif"'>public static void main(String args[]) {<o:p></o:p></span></p><p class=MsoNormal><span class=apple-tab-span><span style='font-size:8.5pt;font-family:"Menlo","serif"'>                                </span></span><span style='font-size:8.5pt;font-family:"Menlo","serif"'>try {<o:p></o:p></span></p><p class=MsoNormal><span class=apple-tab-span><span style='font-size:8.5pt;font-family:"Menlo","serif"'>                                                </span></span><span style='font-size:8.5pt;font-family:"Menlo","serif"'>System.setSecurityManager(new NoExitSecurityManager());<o:p></o:p></span></p><p class=MsoNormal><span class=apple-tab-span><span style='font-size:8.5pt;font-family:"Menlo","serif"'>                                                </span></span><span style='font-size:8.5pt;font-family:"Menlo","serif"'>for (int a = 0; a < args.length; a++) {<o:p></o:p></span></p><p class=MsoNormal><span class=apple-tab-span><span style='font-size:8.5pt;font-family:"Menlo","serif"'>                                                                </span></span><span style='font-size:8.5pt;font-family:"Menlo","serif"'>try {<o:p></o:p></span></p><p class=MsoNormal><span class=apple-tab-span><span style='font-size:8.5pt;font-family:"Menlo","serif"'>                                                                                </span></span><span style='font-size:8.5pt;font-family:"Menlo","serif"'>System.err.println("BEGIN "+args[a]);<o:p></o:p></span></p><p class=MsoNormal><span class=apple-tab-span><span style='font-size:8.5pt;font-family:"Menlo","serif"'>                                                                                </span></span><span style='font-size:8.5pt;font-family:"Menlo","serif"'>net.sf.saxon.Transform.main(new String[] {<o:p></o:p></span></p><p class=MsoNormal><span class=apple-tab-span><span style='font-size:8.5pt;font-family:"Menlo","serif"'>                                                                                                                                </span></span><span style='font-size:8.5pt;font-family:"Menlo","serif"'>"-warnings:recover",<o:p></o:p></span></p><p class=MsoNormal><span class=apple-tab-span><span style='font-size:8.5pt;font-family:"Menlo","serif"'>                                                                                                                                </span></span><span style='font-size:8.5pt;font-family:"Menlo","serif"'>"-o",<o:p></o:p></span></p><p class=MsoNormal><span class=apple-tab-span><span style='font-size:8.5pt;font-family:"Menlo","serif"'>                                                                                                                                </span></span><span style='font-size:8.5pt;font-family:"Menlo","serif"'>args[a].substring(0, args[a].lastIndexOf("."))+".json",<o:p></o:p></span></p><p class=MsoNormal><span class=apple-tab-span><span style='font-size:8.5pt;font-family:"Menlo","serif"'>                                                                                                                                </span></span><span style='font-size:8.5pt;font-family:"Menlo","serif"'>args[a],<o:p></o:p></span></p><p class=MsoNormal><span class=apple-tab-span><span style='font-size:8.5pt;font-family:"Menlo","serif"'>                                                                                                                                </span></span><span style='font-size:8.5pt;font-family:"Menlo","serif"'>"X3dToJson.xslt" });<o:p></o:p></span></p><p class=MsoNormal><span class=apple-tab-span><span style='font-size:8.5pt;font-family:"Menlo","serif"'>                                                                                </span></span><span style='font-size:8.5pt;font-family:"Menlo","serif"'>// -t  #timing -c # compiled<o:p></o:p></span></p><p class=MsoNormal><span class=apple-tab-span><span style='font-size:8.5pt;font-family:"Menlo","serif"'>                                                                                </span></span><span style='font-size:8.5pt;font-family:"Menlo","serif"'>System.err.println("END "+args[a]);<o:p></o:p></span></p><p class=MsoNormal><span class=apple-tab-span><span style='font-size:8.5pt;font-family:"Menlo","serif"'>                                                                </span></span><span style='font-size:8.5pt;font-family:"Menlo","serif"'>} catch (Throwable e) {<o:p></o:p></span></p><p class=MsoNormal><span class=apple-tab-span><span style='font-size:8.5pt;font-family:"Menlo","serif"'>                                                                                </span></span><span style='font-size:8.5pt;font-family:"Menlo","serif"'>System.err.println("FATAL "+args[a]);<o:p></o:p></span></p><p class=MsoNormal><span class=apple-tab-span><span style='font-size:8.5pt;font-family:"Menlo","serif"'>                                                                                </span></span><span style='font-size:8.5pt;font-family:"Menlo","serif"'>System.err.println(e.getMessage());<o:p></o:p></span></p><p class=MsoNormal><span class=apple-tab-span><span style='font-size:8.5pt;font-family:"Menlo","serif"'>                                                                </span></span><span style='font-size:8.5pt;font-family:"Menlo","serif"'>}<o:p></o:p></span></p><p class=MsoNormal><span class=apple-tab-span><span style='font-size:8.5pt;font-family:"Menlo","serif"'>                                                </span></span><span style='font-size:8.5pt;font-family:"Menlo","serif"'>}<o:p></o:p></span></p><p class=MsoNormal><span class=apple-tab-span><span style='font-size:8.5pt;font-family:"Menlo","serif"'>                                                </span></span><span style='font-size:8.5pt;font-family:"Menlo","serif"'>System.setSecurityManager(null); // or save and restore original<o:p></o:p></span></p><p class=MsoNormal><span class=apple-tab-span><span style='font-size:8.5pt;font-family:"Menlo","serif"'>                                </span></span><span style='font-size:8.5pt;font-family:"Menlo","serif"'>} catch (ExitException ee) {<o:p></o:p></span></p><p class=MsoNormal><span class=apple-tab-span><span style='font-size:8.5pt;font-family:"Menlo","serif"'>                                                </span></span><span style='font-size:8.5pt;font-family:"Menlo","serif"'>ee.printStackTrace();<o:p></o:p></span></p><p class=MsoNormal><span class=apple-tab-span><span style='font-size:8.5pt;font-family:"Menlo","serif"'>                                </span></span><span style='font-size:8.5pt;font-family:"Menlo","serif"'>}<o:p></o:p></span></p><p class=MsoNormal><span class=apple-tab-span><span style='font-size:8.5pt;font-family:"Menlo","serif"'>                </span></span><span style='font-size:8.5pt;font-family:"Menlo","serif"'>}<o:p></o:p></span></p><p class=MsoNormal><span style='font-size:8.5pt;font-family:"Menlo","serif"'>}<o:p></o:p></span></p><div><p class=MsoNormal><span style='font-size:8.5pt;font-family:"Menlo","serif"'><br><br><o:p></o:p></span></p></div></div></div></body></html>