[x3d-public] MFString quoting [was: interesting sample] JSON escaping example
Roy Walmsley
roy.walmsley at ntlworld.com
Thu Apr 27 03:22:32 PDT 2017
Hi,
The trick when considering translating from XML encoding to JSON encoding is to think of the what is needed in the middle, i.e. what is loaded into memory, or, equivalently, what would be displayed on the screen. So, considering the examples below one at a time:
X3D "quote mark \" is ""
I presume that the term X3D implies that we looking at an XML encoding of a string. So, what we want to see on the screen is
quote mark " is "
The escaping rules for JSON are simple. An easy to understand diagram is at http://www.json.org/. So translating this memory representation to the JSON encoding gives:
"quote mark \" is ""
Notice that the ampersand shall not be escaped in the JSON encoding. In fact, only the quotation mark " and the reverse solidus \ have to be escaped. The escaping of the forward solidus / is optional.
Now let's look at the second example.
JSON "empty string \\\\\"\\\\\" skips a line:",
This is already a JSON encoding. So a parser will load this and display the following string
empty string \\"\\" skips a line:
Clearly that is not what is desired. What you want to see is:
empty string "" skips a line:
So, encoded into JSON this becomes
"empty string \"\" skips a line:"
Similarly, encoded into the XML encoding gives
"empty string \"\" skips a line:"
So yes, I would conclude that you are far too zealous in adding all those backslashes.
Remember, you are not trying to write an XML encoded string as a JSON encoding. You are going via computer memory, where loading the XML encoding undoes all the escaping. You then only have to do the new escaping on the unescaped string.
Hope this helps. Happy to talk if you want. Especially as I haven't involved stylesheets in the discussion above!
All the best,
Roy
-----Original Message-----
From: x3d-public [mailto:x3d-public-bounces at web3d.org] On Behalf Of Don Brutzman
Sent: 27 April 2017 03:30
To: John Carlson <yottzumm at gmail.com>
Cc: x3d-public at web3d.org
Subject: Re: [x3d-public] MFString quoting [was: interesting sample] JSON escaping example
On 4/26/2017 4:02 PM, yottzumm at gmail.com wrote:
> I do have a problem with the JSON encoding for the attached file (translated by X3dToJson.xslt). Let me know if you think otherwise. Look at all the \\\\\.
i suspect the issue is illustrated by the following SFString within an MFString
X3D "quote mark \" is ""
JSON "empty string \\\\\"\\\\\" skips a line:",
will try to break it down.
double-backslash escaping going on here for JSON; so internal content-only correspondences should likely be
[X3D ] \
[JSON] \\
[X3D ] "
[JSON] \"
[X3D ] \"
[JSON] \\\"
[X3D ] quote mark \" is "
[JSON] quote mark \\\" is "
please count. does that look right?
if so, then it looks like the X3dToJson.xslt is overzealously prepending 2 extra backslashes in this particular case (one of several).
if not, then please advise what the right answer is.
also please re-advise, where are the JSON backslash-related rules?
if we can agree on what the right answer looks like, then i will dive back into the independently XML/XSLT/XPath escaped (and obtw recursive) stylesheet template that consumes/produces this stuff to try doing the job correctly. (gulp!)
p.s. if anyone out there isn't dizzy yet, congrats!
> Sent from Mail <https://go.microsoft.com/fwlink/?LinkId=550986> for Windows 10
>
> *From: *Andreas Plesch <mailto:andreasplesch at gmail.com>
> *Sent: *Wednesday, April 26, 2017 5:21 PM
> *To: *John Carlson <mailto:yottzumm at gmail.com>
> *Cc: *Don Brutzman <mailto:brutzman at nps.edu>; X3D Graphics public mailing list <mailto:x3d-public at web3d.org>
> *Subject: *Re: [x3d-public] MFString quoting [was: interesting sample]
>
> On Wed, Apr 26, 2017 at 3:55 PM, <yottzumm at gmail.com <mailto:yottzumm at gmail.com>> wrote:
>
> It’s
>
> http://x3dgraphics.com/slidesets/X3dForWebAuthors/Chapter02GeometryPrimitives.pdf
>
> Got caught in the grand renaming. Also the parent page is wrong.
>
> Thanks.
all the best, Don
--
Don Brutzman Naval Postgraduate School, Code USW/Br brutzman at nps.edu
Watkins 270, MOVES Institute, Monterey CA 93943-5000 USA +1.831.656.2149
X3D graphics, virtual worlds, navy robotics http://faculty.nps.edu/brutzman
_______________________________________________
x3d-public mailing list
x3d-public at web3d.org
http://web3d.org/mailman/listinfo/x3d-public_web3d.org
More information about the x3d-public
mailing list