<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
</head>
<body text="#000000" bgcolor="#FFFFFF">
<div class="moz-cite-prefix">On 3/20/2018 1:07 PM, John Carlson
wrote:<br>
</div>
<blockquote type="cite"
cite="mid:5ab169f8.0609370a.29985.ffc2@mx.google.com">
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<meta name="Generator" content="Microsoft Word 15 (filtered
medium)">
<style><!--
/* Font Definitions */
@font-face
{font-family:"Cambria Math";
panose-1:2 4 5 3 5 4 6 3 2 4;}
@font-face
{font-family:Calibri;
panose-1:2 15 5 2 2 2 4 3 2 4;}
/* Style Definitions */
p.MsoNormal, li.MsoNormal, div.MsoNormal
{margin:0in;
margin-bottom:.0001pt;
font-size:11.0pt;
font-family:"Calibri",sans-serif;
color:windowtext;}
a:link, span.MsoHyperlink
{mso-style-priority:99;
color:blue;
text-decoration:underline;}
a:visited, span.MsoHyperlinkFollowed
{mso-style-priority:99;
color:#954F72;
text-decoration:underline;}
pre
{mso-style-priority:99;
mso-style-link:"HTML Preformatted Char";
margin:0in;
margin-bottom:.0001pt;
font-size:10.0pt;
font-family:"Courier New";
color:black;}
span.HTMLPreformattedChar
{mso-style-name:"HTML Preformatted Char";
mso-style-priority:99;
mso-style-link:"HTML Preformatted";
font-family:"Courier New";
color:black;}
.MsoChpDefault
{mso-style-type:export-only;}
@page WordSection1
{size:8.5in 11.0in;
margin:1.0in 1.0in 1.0in 1.0in;}
div.WordSection1
{page:WordSection1;}
--></style>
<div class="WordSection1">
<p class="MsoNormal">Since I convert from X3D XML to X3D JSON
and back, the only real problems are differences between the
two formats. If I were converting from VRML to X3D JSON and
back, the issues might be different. I think, but am not
sure, that X3D JSON is more similar to VRML in its structure
etc. However, I am not familiar with VRML.</p>
</div>
</blockquote>
<br>
John,<br>
<br>
Some of the issues are intrinsic to the format. There are
numbers/values vs. strings as you mention below, different ways of
dealing with arrays (also indirectly mentioned below), and comments
(not mentioned). JSON does not have provisions for comments (text
that is not stored in the object). Douglas Crockford (creator of
JSON) offers four reasons at
<a class="moz-txt-link-freetext" href="https://groups.yahoo.com/neo/groups/json/conversations/topics/156">https://groups.yahoo.com/neo/groups/json/conversations/topics/156</a>.
[Lots of other links:
<a class="moz-txt-link-freetext" href="https://stackoverflow.com/questions/244777/can-comments-be-used-in-json">https://stackoverflow.com/questions/244777/can-comments-be-used-in-json</a>]<br>
<br>
1) Numbers/values: Part (perhaps most) of this difficulty lies in
the way X3D encodes multi-element values into strings. Numeric
vectors are not too bad, but I can see where some representations
are difficult to handle. Is it true that once an XML file is parsed
and internally stored, creating the equivalent JSON (at least as far
as value conversions) is relatively easy?<br>
<br>
2) Perhaps it would be better to change the XML encoding for V4 to
reduce the variability of individual elements and elements that are
part of an array.<br>
<br>
3) As I understand the X3D definition of JSON encoding, XML comments
are converted into JSON data elements. If that is the case, an X3D
application (meaning an application that ingests X3D data) should be
able to modify the comments are create output in XML by modifying
the data structure represented by JSON. That may not be possible if
the input was XML and the application was using a valid XML parser
as comments are not part of the XML document's character data. (see
<a class="moz-txt-link-freetext" href="https://www.w3.org/TR/2006/REC-xml11-20060816/#sec-comments">https://www.w3.org/TR/2006/REC-xml11-20060816/#sec-comments</a>).<br>
<br>
Leonard Daly<br>
<br>
<br>
<br>
<blockquote type="cite"
cite="mid:5ab169f8.0609370a.29985.ffc2@mx.google.com">
<div class="WordSection1">
<p class="MsoNormal"><o:p> </o:p></p>
<p class="MsoNormal">It might be best to look at my code to see
where the difficulties like.</p>
<p class="MsoNormal"><o:p> </o:p></p>
<p class="MsoNormal">I recommend DOM2JSONSerializer.js,
X3DJSONLD.js in <a
href="https://github.com/coderextreme/X3DJSONLD/tree/master/src/main/node"
moz-do-not-send="true">https://github.com/coderextreme/X3DJSONLD/tree/master/src/main/node</a>
and some of the serializers which traverse JSON instead of DOM
show the issue better. In general, if we didn’t rely on so
much information derived from the X3D Unified Object Model,
and there was more of a direct transformation between
encodings and source code encodings (JavaScriptSerializer.js,
PythonSerializer.js, JavaSerializer.js), without knowledge of
external sources (mapToMethod*.js, fieldTypes.js), that would
be good, too.</p>
<p class="MsoNormal"><o:p> </o:p></p>
<p class="MsoNormal">Mostly the problem is containerFields I
think. If container Fields were treated more similar to XML,
it might be easier. It might also be better to review the
requirements of X3D JSON with regards to unordering and
ordering of nodes, statements, etc. If we assumed order did
not necessarily mean order, it would be easier, I think.</p>
<p class="MsoNormal"><o:p> </o:p></p>
<p class="MsoNormal">Various links of interest:</p>
<p class="MsoNormal"><o:p> </o:p></p>
<p class="MsoNormal"><a
href="http://www.web3d.org/x3d/stylesheets/X3dToJson.html"
moz-do-not-send="true">http://www.web3d.org/x3d/stylesheets/X3dToJson.html</a></p>
<p class="MsoNormal"><o:p> </o:p></p>
<p class="MsoNormal"><a
href="http://www.web3d.org/wiki/index.php/X3D_JSON_Encoding"
moz-do-not-send="true">http://www.web3d.org/wiki/index.php/X3D_JSON_Encoding</a></p>
<p class="MsoNormal"><o:p> </o:p></p>
<p class="MsoNormal"><o:p> </o:p></p>
<p class="MsoNormal">I just don’t think we can get to the
simpler tools, without banging our users over the head. But
we are really banging the programmers on the head, at the
expense of 1) making the encoding meet the requirements,
instead of using JSON more like XML.</p>
<p class="MsoNormal"><o:p> </o:p></p>
<p class="MsoNormal">One more thing. If type was required in
fieldValue, I wouldn’t have to look it up in the field. Minor
nit that I have fixed.</p>
<p class="MsoNormal"><o:p> </o:p></p>
<p class="MsoNormal">John</p>
<p class="MsoNormal"><o:p> </o:p></p>
<p class="MsoNormal">Sent from <a
href="https://go.microsoft.com/fwlink/?LinkId=550986"
moz-do-not-send="true">Mail</a> for Windows 10</p>
<p class="MsoNormal"><o:p> </o:p></p>
<div
style="mso-element:para-border-div;border:none;border-top:solid
#E1E1E1 1.0pt;padding:3.0pt 0in 0in 0in">
<p class="MsoNormal" style="border:none;padding:0in"><b>From:
</b><a href="mailto:Leonard.Daly@realism.com"
moz-do-not-send="true">Leonard Daly</a><br>
<b>Sent: </b>Tuesday, March 20, 2018 3:08 PM<br>
<b>To: </b><a href="mailto:yottzumm@gmail.com"
moz-do-not-send="true">John Carlson</a>; <a
href="mailto:x3d-public@web3d.org" moz-do-not-send="true">x3d-public@web3d.org</a><br>
<b>Subject: </b>Re: [x3d-public] X3DJSONLD ... converts XML
to JSON client side!</p>
</div>
<p class="MsoNormal"><o:p> </o:p></p>
<p class="MsoNormal" style="margin-bottom:12.0pt">John,<br>
<br>
It appears to me that your biggest/most-important request is
to define a nice/simpler JSON encoding for X3D than the one
currently being used. I am going to continue this discussion
based on that assumption. If it is not the case, please
clarify.<br>
<br>
You have been working with this for quite some time. My
experience is in general JSON, not necessarily the X3D flavor.
Can you describe what is currently difficult or complex in the
current X3D-Json flavor. There is no sense on redoing/revising
what is currently working well. What I would like to
understand is the top 3-5 difficult or messy conversion issues
and what makes them messy. <br>
<br>
Thanks,<br>
<br>
Leonard Daly<br>
<br>
<br>
<o:p></o:p></p>
<blockquote style="margin-top:5.0pt;margin-bottom:5.0pt">
<p class="MsoNormal">Because X3D JSON is very different from
X3D XML. They don’t map well with standard methods.<o:p></o:p></p>
<p class="MsoNormal"> <o:p></o:p></p>
<p class="MsoNormal">Yes, it will take a little more work to
handle circular dependencies, and all the extra variables in
DOM.<o:p></o:p></p>
<p class="MsoNormal"> <o:p></o:p></p>
<p class="MsoNormal">Are you proposing
JSON.stringify(xmlDom)? I think that would generate way to
much data, and XMLSerializer would work better, but
XMLSerializer produces XML. But that’s essentially what
DOM2JSONSerializer is, serializes DOM to X3D JSON. Duh!<o:p></o:p></p>
<p class="MsoNormal"> <o:p></o:p></p>
<p class="MsoNormal">The revolution here is that I can do it
client side. I already had X3dToJson.xslt to do it server
side. X3dToJson.xslt doesn’t work client side, last I
checked.<o:p></o:p></p>
<p class="MsoNormal"> <o:p></o:p></p>
<p class="MsoNormal">I don’t think you’ve found the golden egg
yet, Leonard, but see below.<o:p></o:p></p>
<p class="MsoNormal"> <o:p></o:p></p>
<p class="MsoNormal">John<o:p></o:p></p>
<p class="MsoNormal"> <o:p></o:p></p>
<p class="MsoNormal">I encourage you to propose an X3D JSON
standard based on this to see if it will fly. Send some
PROTO examples to the mailing list—believe me, I tried. The
first step is to standardize X3D JSON, not find an XML to
JSON converter. But to finalize the X3D JSON standard, we
need two implementations. Now we have 2 implementations.<o:p></o:p></p>
<p class="MsoNormal"> <o:p></o:p></p>
<p class="MsoNormal">Please proposed an X3D JSON standard that
is simpler, PLEASE????<o:p></o:p></p>
<p class="MsoNormal"> <o:p></o:p></p>
<p class="MsoNormal">Thanks!<o:p></o:p></p>
<p class="MsoNormal"> <o:p></o:p></p>
<p class="MsoNormal">Sent from <a
href="https://go.microsoft.com/fwlink/?LinkId=550986"
moz-do-not-send="true">Mail</a> for Windows 10<o:p></o:p></p>
<p class="MsoNormal"> <o:p></o:p></p>
<div style="border:none;border-top:solid #E1E1E1
1.0pt;padding:3.0pt 0in 0in 0in">
<p class="MsoNormal"><b>From: </b><a
href="mailto:Leonard.Daly@realism.com"
moz-do-not-send="true">Leonard Daly</a><br>
<b>Sent: </b>Tuesday, March 20, 2018 11:30 AM<br>
<b>To: </b><a href="mailto:x3d-public@web3d.org"
moz-do-not-send="true">x3d-public@web3d.org</a><br>
<b>Subject: </b>Re: [x3d-public] X3DJSONLD ... converts
XML to JSON client side!<o:p></o:p></p>
</div>
<p class="MsoNormal"> <o:p></o:p></p>
<p class="MsoNormal" style="margin-bottom:12.0pt"><span
style="color:black">John,<br>
<br>
I am wondering how this might differ from the following
built-in capabilities described below. What does your code
do differently than these built-in methods?<br>
<br>
<br>
XD is an (string) XML fragment, then this fragment can be
inserted into the DOM (either as part of the document of a
separate sub-tree) using<br>
<br>
var parser = new DOMParser();<br>
var xmlDom = parser.parserFromString (XD,
'application/xml');<br>
<br>
[Ref: <a
href="https://developer.mozilla.org/en-US/docs/Web/API/DOMParser"
moz-do-not-send="true">https://developer.mozilla.org/en-US/docs/Web/API/DOMParser</a>]<br>
<br>
At this point xmlDom is a DOM tree, but not inserted into
the HTML document DOM.<br>
<br>
It is possible to go back to XML string using<br>
<br>
var S = new XMLSerializer();<br>
var xmlString = s.serializeToString (xmlDom);<br>
<br>
[Ref: <a
href="https://developer.mozilla.org/en-US/docs/Web/API/XMLSerializer"
moz-do-not-send="true">https://developer.mozilla.org/en-US/docs/Web/API/XMLSerializer</a>]<br>
<br>
There is the JSON.stringify method <br>
<br>
[Ref: <a
href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/JSON/stringify"
moz-do-not-send="true">https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/JSON/stringify</a>
and <a
href="https://stackoverflow.com/questions/46880822/how-to-json-stringify-a-dom-element"
moz-do-not-send="true">https://stackoverflow.com/questions/46880822/how-to-json-stringify-a-dom-element</a>
- answer 1]<br>
<br>
There is at least one other GItHub project (<a
href="https://gist.github.com/sstur/7379870"
moz-do-not-send="true">https://gist.github.com/sstur/7379870</a>)
that converts to/from JSON and strings/DOM.<br>
<br>
Going from an internal object to JSON takes a little
careful work to make sure the tree is correctly handled
and the code does not follow the circular loops that are
present in DOM.<br>
<br>
<br>
Leonard Daly<br>
<br>
<br>
<br>
<br>
</span><o:p></o:p></p>
<blockquote style="margin-top:5.0pt;margin-bottom:5.0pt">
<p class="MsoNormal"><span style="color:black">The X3D JSON
Loader now converts XML to JSON client-side, for your
nefarious purposes!</span><o:p></o:p></p>
<p class="MsoNormal"><span style="color:black"> </span><o:p></o:p></p>
<p class="MsoNormal"><span style="color:black"><a
href="https://coderextreme.net/X3DJSONLD/src/main/html/index.html"
moz-do-not-send="true">https://coderextreme.net/X3DJSONLD/src/main/html/index.html</a></span><o:p></o:p></p>
<p class="MsoNormal"><span style="color:black"> </span><o:p></o:p></p>
<p class="MsoNormal"><span style="color:black">Enjoy
loading!</span><o:p></o:p></p>
<p class="MsoNormal"><span style="color:black"> </span><o:p></o:p></p>
<p class="MsoNormal"><span style="color:black">John</span><o:p></o:p></p>
<p class="MsoNormal"><span style="color:black"><br>
<br>
<br>
<br>
</span><o:p></o:p></p>
<pre>_______________________________________________</pre>
<pre>x3d-public mailing list</pre>
<pre><a href="mailto:x3d-public@web3d.org" moz-do-not-send="true">x3d-public@web3d.org</a></pre>
<pre><a href="http://web3d.org/mailman/listinfo/x3d-public_web3d.org" moz-do-not-send="true">http://web3d.org/mailman/listinfo/x3d-public_web3d.org</a></pre>
</blockquote>
<p> </p>
<p class="MsoNormal"><span style="color:black">-- <br>
</span><b><span style="font-size:13.5pt;color:#333366">Leonard
Daly</span></b><span style="color:#333366"><br>
3D Systems & Cloud Consultant<br>
LA ACM SIGGRAPH Past Chair<br>
President, Daly Realism - <i>Creating the Future</i> </span><o:p></o:p></p>
<p class="MsoNormal"><span style="color:black"> </span><o:p></o:p></p>
</blockquote>
<p><o:p> </o:p></p>
<p class="MsoNormal"><span style="color:black">-- <br>
</span><b><span style="font-size:13.5pt;color:#333366">Leonard
Daly</span></b><span style="color:#333366"><br>
3D Systems & Cloud Consultant<br>
LA ACM SIGGRAPH Past Chair<br>
President, Daly Realism - <i>Creating the Future</i> </span><span
style="color:black"><o:p></o:p></span></p>
<p class="MsoNormal"><o:p> </o:p></p>
</div>
</blockquote>
<p><br>
</p>
<div class="moz-signature">-- <br>
<font class="tahoma,arial,helvetica san serif" color="#333366">
<font size="+1"><b>Leonard Daly</b></font><br>
3D Systems & Cloud Consultant<br>
LA ACM SIGGRAPH Past Chair<br>
President, Daly Realism - <i>Creating the Future</i>
</font></div>
</body>
</html>