<div dir="ltr"><div><div><div><div><div>Hi John,<br><br></div>So I took the next step and used the DOMParser method to produce a CDATASection for html documents in my cdata branch:<br><br><a href="https://github.com/andreasplesch/X3DJSONLD/blob/cdata/X3DJSONLD.js#L224">https://github.com/andreasplesch/X3DJSONLD/blob/cdata/X3DJSONLD.js#L224</a><br><br></div>Using this method the script in the example work for both html and xhtml:<br><br><a href="https://rawgit.com/andreasplesch/X3DJSONLD/cdata/AP_minimal_JSLD.html">https://rawgit.com/andreasplesch/X3DJSONLD/cdata/AP_minimal_JSLD.html</a><br><a href="https://rawgit.com/andreasplesch/X3DJSONLD/cdata/AP_minimal_JSLD.xhtml">https://rawgit.com/andreasplesch/X3DJSONLD/cdata/AP_minimal_JSLD.xhtml</a><br><br></div>in cobweb.<br><br></div>Cobweb expects to see a CDATASection node. It ignores all text nodes. This is reasonable since using a cdata section is strongly recommended in the x3d encoding spec.<br><br></div>I issued a PR in case you are interested in adopting this:<br><br><div><div><div><div><div><a href="https://github.com/coderextreme/X3DJSONLD/pull/4">https://github.com/coderextreme/X3DJSONLD/pull/4</a><br><br></div><div>-Andreas<br></div><div><br></div></div></div></div></div></div><div class="gmail_extra"><br><div class="gmail_quote">On Sun, Dec 4, 2016 at 3:42 PM, Andreas Plesch <span dir="ltr"><<a href="mailto:andreasplesch@gmail.com" target="_blank">andreasplesch@gmail.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr"><div><div><div>Hi John,<br><br></div>I saw that you already tried createCDATASection but commented that perhaps because it did not work for html. I reenabled createCDATASection here:<br><br><a href="https://github.com/andreasplesch/X3DJSONLD/blob/master/X3DJSONLD.js#L235" target="_blank">https://github.com/<wbr>andreasplesch/X3DJSONLD/blob/<wbr>master/X3DJSONLD.js#L235</a><br><br></div>and with that change the simple script example works (!) in an xhtml document:<br><br><a href="https://rawgit.com/andreasplesch/X3DJSONLD/master/AP_minimal_JSLD.xhtml" target="_blank">https://rawgit.com/<wbr>andreasplesch/X3DJSONLD/<wbr>master/AP_minimal_JSLD.xhtml</a><br><br></div>-Andreas<br><div><div><br></div></div></div><div class="gmail_extra"><br><div class="gmail_quote">On Sun, Dec 4, 2016 at 3:31 PM, Andreas Plesch <span dir="ltr"><<a href="mailto:andreasplesch@gmail.com" target="_blank">andreasplesch@gmail.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr"><div><div>Hi John,<br><br></div>I looked at the <a href="http://www.web3d.org/x3d/content/examples/Basic/ScriptConformance/TouchSensorIsOverEventECMAScript.json" target="_blank">http://www.web3d.org/x3d/conte<wbr>nt/examples/Basic/ScriptConfor<wbr>mance/TouchSensorIsOverEventEC<wbr>MAScript.json</a> example.<br><br></div>The problem is that X3DJSONLD turns the script node into a DOM node with correct field node children but the script text is contained in raw text nodes:<br><div><div><div><br><field><br><field><br><div>#text "<![CDATA["<br>#text "ecmascript:function isOver(val) { if (val == true) { diffuseColor_changed = new SFColor(1,0,0); } else { diffuseColor_changed = new SFColor(0,0,1); }}"<br>#text "]]>"<br><br></div><div>The script text should be contained in the nodeValue/textContent of a CDATASection :<br></div><div><br><field><br><field><br>CDATASection nodeValue=textContent="ecmascr<wbr>ipt:function isOver(val) { if (val == true) {
diffuseColor_changed = new SFColor(1,0,0); } else {
diffuseColor_changed = new SFColor(0,0,1); }}"<br><br><a href="https://developer.mozilla.org/en-US/docs/Web/API/Document/createCDATASection" target="_blank">https://developer.mozilla.org/<wbr>en-US/docs/Web/API/Document/cr<wbr>eateCDATASection</a><br><br></div><div>However, createCDATASection only works with xhtml.<br><br></div><div>I am sneaking a CDATASection into a html document using DOMParser in xml mode here:<br><br><a href="https://github.com/andreasplesch/cobweb_dom/blob/master/cobweb/cobweb_dom.js#L34" target="_blank">https://github.com/andreasples<wbr>ch/cobweb_dom/blob/master/<wbr>cobweb/cobweb_dom.js#L34</a><br><br></div><div>I think DOMParser.parseFromString("<![<wbr>CDATA[ scripttext using > and < ]]>", <span class="m_-2059514568631322761m_-7590909182361465553gmail-pl-s"><span class="m_-2059514568631322761m_-7590909182361465553gmail-pl-pds">'</span>application/xml<span class="m_-2059514568631322761m_-7590909182361465553gmail-pl-pds">'</span></span>); should return a document with a single cdatasection node which then can be appended to the script node.<br><br><a href="https://github.com/coderextreme/X3DJSONLD/blob/master/X3DJSONLD.js#L224" target="_blank">https://github.com/coderextrem<wbr>e/X3DJSONLD/blob/master/<wbr>X3DJSONLD.js#L224</a><br><br></div><div>looks like the function where an actual CDATASection node needs to be created instead of raw text nodes.<br></div><div><br></div><div>Hope this helps,<br><br></div><div>Andreas<br></div><div class="gmail_extra"><br><div class="gmail_quote">On Sun, Dec 4, 2016 at 1:42 PM, Andreas Plesch <span dir="ltr"><<a href="mailto:andreasplesch@gmail.com" target="_blank">andreasplesch@gmail.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><div dir="ltr"><p dir="ltr">Hi John,</p>
<p dir="ltr">X3dom is designed to work with the XML encoding or a dom. So for x3dom it would be necessary to first create a DOM from the json. It will be difficult to get around that.<br></p>
<p dir="ltr">Cobweb has parsers which parse XML or vrml into a scene graph. So it should be possible to make a parser for json, probably following what the XML parser does. But the easier path would be also to create a DOM from the json first.</p><p>How do you envision you or others would use json encoded x3d content to add value to a project ? Easier manipulation as a js object ? Easier programmatic content creation ? As an exchange/transmission format, a bit similar to gltf ?<br></p><p><br></p><p><a href="http://www.web3d.org/x3d/content/examples/Basic/ScriptConformance/" target="_blank">http://www.web3d.org/x3d/conte<wbr>nt/examples/Basic/ScriptConfor<wbr>mance/</a></p><p>has good examples to test scripting. For example,<br></p><p><a href="http://www.web3d.org/x3d/content/examples/Basic/ScriptConformance/TouchSensorIsOverEventECMAScriptIndex.html" target="_blank">http://www.web3d.org/x3d/conte<wbr>nt/examples/Basic/ScriptConfor<wbr>mance/TouchSensorIsOverEventEC<wbr>MAScriptIndex.html</a><br></p><p dir="ltr"><a href="http://www.web3d.org/x3d/content/examples/Basic/ScriptConformance/TouchSensorIsOverEventECMAScript.json" target="_blank">http://www.web3d.org/x3d/conte<wbr>nt/examples/Basic/ScriptConfor<wbr>mance/TouchSensorIsOverEventEC<wbr>MAScript.json</a></p><p>I may give this example a try with the json loader and cobweb.<br></p><p>-Andreas</p><div class="gmail_extra"><br><div class="gmail_quote">On Dec 4, 2016 1:49 AM, "John Carlson" <<a href="mailto:yottzumm@gmail.com" target="_blank">yottzumm@gmail.com</a>> wrote:<br type="attribution"><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><p dir="ltr">Perhaps it's time for me to dig into Cobweb and X3DOM to see how they can be extended to support JSON? If it's through DOM, which is fine by me, I would have to look and see how the various encodings are loaded after DOM is loaded.</p>
<div class="gmail_extra"><br><div class="gmail_quote">On Dec 4, 2016 1:40 AM, "John Carlson" <<a href="mailto:yottzumm@gmail.com" target="_blank">yottzumm@gmail.com</a>> wrote:<br type="attribution"><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><p dir="ltr">Again, the X3D JSON Loader is a proof of concept patch until we get full JSON support in Cobweb and X3DOM, if desired.</p>
<div class="gmail_extra"><br><div class="gmail_quote">On Dec 4, 2016 1:24 AM, "John Carlson" <<a href="mailto:yottzumm@gmail.com" target="_blank">yottzumm@gmail.com</a>> wrote:<br type="attribution"><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><p dir="ltr">Because I may not have the full x3d examples downloaded. And I do want to test to see if JSON inclusion works.</p>
<div class="gmail_extra"><br><div class="gmail_quote">On Dec 2, 2016 3:04 PM, "Andreas Plesch" <<a href="mailto:andreasplesch@gmail.com" target="_blank">andreasplesch@gmail.com</a>> wrote:<br type="attribution"><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><div dir="ltr">Hi John,<div><br></div><div>I tried a bit to load gears.json with X3DJSONLD:</div><div><br></div><div><a href="https://raw.githubusercontent.com/andreasplesch/X3DJSONLD/master/AP_minimal_JSLD.html" target="_blank">https://raw.githubusercontent.<wbr>com/andreasplesch/X3DJSONLD/ma<wbr>ster/AP_minimal_JSLD.html</a><br></div><div><br></div><div>But even before any script parsing/loading, there is a problem with the ExternProtoDeclare node in gears.json. It has a url field to Rotor.x3d which is replaced by the json loader with Rotor.json before being handed off to cobweb with importDocument(). Cobweb does not know what to do with the Rotor.json file and gives up.</div><div><br></div><div>Why modify the url field value ? If the scene author wants to use a .json encoded scene, she will put it in the url field just like a .wrl encoded scene.</div><div><br></div><div>On another note, I agree that eval() cannot be avoided if script should be supported. cobweb itself also uses eval() (after some setup and massaging) to run the x3d script.</div><div><br></div><div>type="application/x-vrmlscript<wbr>" is necessary because without it the web browser will try to run the script "as is" as soon as it gets appended to the page DOM. When cobweb gets a chance to check for the type attribute, it is already too late. So it cannot use the attribute to prevent it from running. It can only not reject it which is what it does.</div><div><br></div><div>-Andreas</div><div><br></div></div><div class="gmail_extra"><br><div class="gmail_quote">On Thu, Dec 1, 2016 at 1:02 AM, <span dir="ltr"><<a href="mailto:yottzumm@gmail.com" target="_blank">yottzumm@gmail.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><div lang="EN-US"><div class="m_-2059514568631322761m_-7590909182361465553gmail-m_-1818107344132003502gmail-m_6814112949669356284m_7174440674528929433m_-637341298042191590m_4670831100320161873m_3334206258020055149m_-8313888796625588714WordSection1"><p class="MsoNormal">It appears that Cobweb is fouled up with DOM loading of scripts, even with the additional name value pair. See gears.x3d/gears.json and load DOM through importDocument. And independent test would help. I am not sure which of my X3DCanvases gets loaded first and I am using absolute indexing, so it could be the XML loaded one that is failing. Basically, we need a good way to load scripts coming in through JSON I think, and the only real way I know how to do it is eval or cobweb with JSON to XML conversion and VRMLscript. If Cobweb could use the VRMLscript from JSON or DOM, that might be ideal.</p><p class="MsoNormal"> </p><p class="MsoNormal">This is with cobweb 2.4.</p><p class="MsoNormal"> </p><p class="MsoNormal">John</p><p class="MsoNormal"> </p><p class="MsoNormal">Sent from <a href="https://go.microsoft.com/fwlink/?LinkId=550986" target="_blank">Mail</a> for Windows 10</p><p class="MsoNormal"> </p><div style="border-width:1pt medium medium;border-style:solid none none;border-color:rgb(225,225,225) -moz-use-text-color -moz-use-text-color;padding:3pt 0in 0in"><p class="MsoNormal" style="border-width:medium;border-style:none;border-color:-moz-use-text-color;padding:0in"><b>From: </b><a href="mailto:yottzumm@gmail.com" target="_blank">yottzumm@gmail.com</a><br><b>Sent: </b>Thursday, December 1, 2016 12:32 AM<br><b>To: </b><a href="mailto:andreasplesch@gmail.com" target="_blank">Andreas Plesch</a>; <a href="mailto:brutzman@nps.edu" target="_blank">Don Brutzman</a>; <a href="mailto:roy.walmsley@ntlworld.com" target="_blank">Roy Walmsley</a><br><b>Subject: </b>FW: loading X3D DOM. Latest Cobweb techniques?</p></div><p class="MsoNormal"> </p><p class="MsoNormal">Would it be possible to get a name/value of </p><p class="MsoNormal"> </p><p class="MsoNormal">"@<span class="m_-2059514568631322761m_-7590909182361465553gmail-m_-1818107344132003502gmail-m_6814112949669356284m_7174440674528929433m_-637341298042191590m_4670831100320161873m_3334206258020055149m_-8313888796625588714html-attribute-name"><span style="font-size:13.5pt;font-family:"courier new"">type"</span></span><span style="font-size:13.5pt;font-family:"courier new";color:rgb(136,18,128)"> : "</span><span class="m_-2059514568631322761m_-7590909182361465553gmail-m_-1818107344132003502gmail-m_6814112949669356284m_7174440674528929433m_-637341298042191590m_4670831100320161873m_3334206258020055149m_-8313888796625588714html-attribute-value"><span style="font-size:13.5pt;font-family:"courier new"">application/x-vrmlscript"</span></span><span style="font-size:13.5pt;font-family:"courier new";color:rgb(136,18,128)"></span></p><p class="MsoNormal"><span style="font-size:13.5pt;font-family:"courier new";color:rgb(136,18,128)"> </span></p><p class="MsoNormal"><span style="font-size:13.5pt;font-family:"courier new";color:rgb(136,18,128)">On the Script tag in X3D JSON? I will do some testing here first to see if it will help.</span></p><p class="MsoNormal"><span style="font-size:13.5pt;font-family:"courier new";color:rgb(136,18,128)"> </span></p><p class="MsoNormal"><span style="font-size:13.5pt;font-family:"courier new";color:rgb(136,18,128)">John</span></p><p class="MsoNormal"> </p><div style="border-width:1pt medium medium;border-style:solid none none;border-color:rgb(225,225,225) -moz-use-text-color -moz-use-text-color;padding:3pt 0in 0in"><p class="MsoNormal"><b>From: </b><a href="mailto:yottzumm@gmail.com" target="_blank">yottzumm@gmail.com</a><br><b>Sent: </b>Thursday, December 1, 2016 12:24 AM<br><b>To: </b><a href="mailto:andreasplesch@gmail.com" target="_blank">Andreas Plesch</a><br><b>Subject: </b>RE: loading X3D DOM. Latest Cobweb techniques?</p></div><p class="MsoNormal"> </p><p class="MsoNormal">One thing I noticed once I got both DOM and XML views loaded, was that I think the DOM VRML script tag was disabled, but the XML one worked. Was there some attribute to add to the Script tag to make it work? Can I add it in both XML and DOM? Thanks, John I will start email search.</p><p class="MsoNormal"> </p><p class="MsoNormal"> </p><p class="MsoNormal"> </p></div></div></blockquote></div><br><br clear="all"><span class="m_-2059514568631322761HOEnZb"><font color="#888888"><span class="m_-2059514568631322761m_-7590909182361465553gmail-HOEnZb"><font color="#888888"><div><br></div>-- <br><div class="m_-2059514568631322761m_-7590909182361465553gmail-m_-1818107344132003502gmail-m_6814112949669356284m_7174440674528929433m_-637341298042191590m_4670831100320161873m_3334206258020055149gmail_signature">Andreas Plesch<br>39 Barbara Rd.<br>Waltham, MA 02453</div>
</font></span></font></span></div><span class="m_-2059514568631322761HOEnZb"><font color="#888888">
</font></span></blockquote></div></div><span class="m_-2059514568631322761HOEnZb"><font color="#888888">
</font></span></blockquote></div></div><span class="m_-2059514568631322761HOEnZb"><font color="#888888">
</font></span></blockquote></div></div><span class="m_-2059514568631322761HOEnZb"><font color="#888888">
</font></span></blockquote></div></div><span class="m_-2059514568631322761HOEnZb"><font color="#888888">
</font></span></div><span class="m_-2059514568631322761HOEnZb"><font color="#888888">
</font></span></blockquote></div><span class="m_-2059514568631322761HOEnZb"><font color="#888888"><br><br clear="all"><span class="HOEnZb"><font color="#888888"><br>-- <br><div class="m_-2059514568631322761m_-7590909182361465553gmail_signature">Andreas Plesch<br>39 Barbara Rd.<br>Waltham, MA 02453</div>
</font></span></font></span></div></div></div></div></div><span class="HOEnZb"><font color="#888888">
</font></span></blockquote></div><span class="HOEnZb"><font color="#888888"><br><br clear="all"><br>-- <br><div class="m_-2059514568631322761gmail_signature" data-smartmail="gmail_signature">Andreas Plesch<br>39 Barbara Rd.<br>Waltham, MA 02453</div>
</font></span></div>
</blockquote></div><br><br clear="all"><br>-- <br><div class="gmail_signature" data-smartmail="gmail_signature">Andreas Plesch<br>39 Barbara Rd.<br>Waltham, MA 02453</div>
</div>