[x3d-public] X3DJSONLD ... converts XML to JSON client side!

John Carlson yottzumm at gmail.com
Tue Mar 20 13:11:40 PDT 2018


If field values were strings like they are in XML, things would be much simpler.  But the fact is, they aren’t strings, so they shouldn’t be treated like strings in JSON.

That’s a big code multipler.

If there weren’t both SFNode, and MFNode, just MFNode, things would be simpler too.   But for historical purposes, we’re probably keeping SFNodes.

John

Sent from Mail for Windows 10

From: John Carlson
Sent: Tuesday, March 20, 2018 4:07 PM
To: Leonard Daly; x3d-public at web3d.org
Subject: RE: [x3d-public] X3DJSONLD ... converts XML to JSON client side!

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.

It might be best to look at my code to see where the difficulties like.

I recommend DOM2JSONSerializer.js, X3DJSONLD.js in https://github.com/coderextreme/X3DJSONLD/tree/master/src/main/node 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.

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.

Various links of interest:

http://www.web3d.org/x3d/stylesheets/X3dToJson.html

http://www.web3d.org/wiki/index.php/X3D_JSON_Encoding


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.

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.

John

Sent from Mail for Windows 10

From: Leonard Daly
Sent: Tuesday, March 20, 2018 3:08 PM
To: John Carlson; x3d-public at web3d.org
Subject: Re: [x3d-public] X3DJSONLD ... converts XML to JSON client side!

John,

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.

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. 

Thanks,

Leonard Daly

Because X3D JSON is very different from X3D XML.  They don’t map well with standard methods.
 
Yes, it will take a little more work to handle circular dependencies, and all the extra variables in DOM.
 
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!
 
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.
 
I don’t think you’ve found the golden egg yet, Leonard, but see below.
 
John
 
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.
 
Please proposed an X3D JSON standard that is simpler, PLEASE????
 
Thanks!
 
Sent from Mail for Windows 10
 
From: Leonard Daly
Sent: Tuesday, March 20, 2018 11:30 AM
To: x3d-public at web3d.org
Subject: Re: [x3d-public] X3DJSONLD ... converts XML to JSON client side!
 
John,

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?


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

var parser = new DOMParser();
var xmlDom = parser.parserFromString (XD, 'application/xml');

[Ref: https://developer.mozilla.org/en-US/docs/Web/API/DOMParser]

At this point xmlDom is a DOM tree, but not inserted into the HTML document DOM.

It is possible to go back to XML string using

var S = new XMLSerializer();
var xmlString = s.serializeToString (xmlDom);

[Ref: https://developer.mozilla.org/en-US/docs/Web/API/XMLSerializer]

There is the JSON.stringify method 

[Ref: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/JSON/stringify and https://stackoverflow.com/questions/46880822/how-to-json-stringify-a-dom-element - answer 1]

There is at least one other GItHub project (https://gist.github.com/sstur/7379870) that converts to/from JSON and strings/DOM.

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.


Leonard Daly



The X3D JSON Loader now converts XML to JSON client-side, for your nefarious purposes!
 
https://coderextreme.net/X3DJSONLD/src/main/html/index.html
 
Enjoy loading!
 
John



_______________________________________________
x3d-public mailing list
x3d-public at web3d.org
http://web3d.org/mailman/listinfo/x3d-public_web3d.org
 
-- 
Leonard Daly
3D Systems & Cloud Consultant
LA ACM SIGGRAPH Past Chair
President, Daly Realism - Creating the Future 
 

-- 
Leonard Daly
3D Systems & Cloud Consultant
LA ACM SIGGRAPH Past Chair
President, Daly Realism - Creating the Future 


-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://web3d.org/pipermail/x3d-public_web3d.org/attachments/20180320/4245e834/attachment-0001.html>


More information about the x3d-public mailing list