<div dir="ltr"><div dir="ltr"><div dir="ltr"><div dir="ltr">Here are the changes I've made to X3duomToX3dPythonPackage.xslt to make a further advancement in JSON output (hopefully, I've changed nothing else).  I suggest running your unit tests on the results before distribution, or tell me what ant targets to run.  I've provided the full stylesheet (attached) at this point.</div><div dir="ltr"><br></div><div>In particular, see the stuff I've done with JSONListHelper at a minimum.<br><br>The license under x3d-code/<a href="http://www.web3d.org/x3d/stylesheets/license.html">www.web3d.org/x3d/stylesheets/license.html</a> on <a href="http://sourceforge.net">sourceforge.net</a> applies to my work.</div><div><br>The main advances are what I've done with Comments under head, and the JSONListHelper sorting head statements by class, also used with MFNodes).  The rest is probably brace and comma twiddling, though I admit that head looks a lot better than the rest, and I don't think that braces even match up at this point.  The JSON output does not currently work with JSON parsing at all, but it does create a pretty nice head.</div><div><br></div><div>I currently take output from x3djsonld.py (still under development, working on round tripping JSON)  <a href="https://github.com/coderextreme/X3DJSONLD/blob/master/src/main/python/x3djsonld.py">X3DJSONLD/src/main/python/x3djsonld.py at master · coderextreme/X3DJSONLD (github.com)</a></div><div><br></div><div>I would typically run x3djsonld.py like this, piping output from output to remove the welcome header from x3d.py into tail to take it off, then writing to a JSON file.</div><div><br></div><div>$ py x3djsonld.py HelloWorldProgramOutputCanonical.json | py |tail +2 | less<br></div><div><br></div><div>I like using Git for Bash/Git for Windows as my shell instead of cmd or powershell.</div><div><br>Thanks!</div><div><br></div><div>John</div><div dir="ltr"><br></div><div dir="ltr"><br></div></div></div></div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Wed, Jul 19, 2023 at 2:04 PM John Carlson <<a href="mailto:yottzumm@gmail.com">yottzumm@gmail.com</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><div dir="auto">I have many changes to contribute to x3d.py JSON output.  I would not get carried away without my changes!</div><div dir="auto"><br></div><div dir="auto">I have the whole head statement worked out right now.  I have not had to make many changes to x3djson.py.</div><div dir="auto"><br></div><div dir="auto">Be aware that I spent a lot of time getting the Comment class working, at least initially, and I have a JSONListHelper function, which makes it easy to sort through children, I hope </div><div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Wed, Jul 19, 2023 at 8:31 AM Brutzman, Donald (Don) (CIV) <<a href="mailto:brutzman@nps.edu" target="_blank">brutzman@nps.edu</a>> wrote:<br></div><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><p>Thanks for tackling one of the hardest issues John.  Thanks for spot-on analysis Vince.<u></u><u></u></p><p><u></u> <u></u></p><p>Recommendations to keep in mind:<u></u><u></u></p><ol style="margin-top:0in" start="1" type="a"><li>Be very precise about your use of single-quote and double-quote characters.  Then your output is simple and correct.<u></u><u></u></li><li>Slightly different handling rules for SFString and MFString values, based on Python [ list ] square brackets.  <u></u><u></u></li><li>Utility methods in x3d.py permit substituting a simple string for an MFString, but you have to be careful not to smash a list into a single value (as Vince points out).<u></u><u></u></li></ol><p><u></u> <u></u></p><p>Excerpt from<u></u><u></u></p><ul style="margin-top:0in" type="disc"><li><b><i><span style="font-size:12pt;font-family:"Times New Roman",serif;color:black">X3D Example Archives: X3D4WA, X3D for Web Authors, Chapter 04 Viewing Navigation, Navigation Info Example</span></i></b><span style="font-size:8pt"><u></u><u></u></span></li><li><a href="https://www.x3dgraphics.com/examples/X3dForWebAuthors/Chapter04ViewingNavigation/NavigationInfoExampleIndex.html" target="_blank">https://www.x3dgraphics.com/examples/X3dForWebAuthors/Chapter04ViewingNavigation/NavigationInfoExampleIndex.html</a><u></u><u></u></li><li><a href="https://www.x3dgraphics.com/examples/X3dForWebAuthors/Chapter04ViewingNavigation/NavigationInfoExample.py" target="_blank">https://www.x3dgraphics.com/examples/X3dForWebAuthors/Chapter04ViewingNavigation/NavigationInfoExample.py</a><u></u><u></u></li></ul><p><u></u> <u></u></p><p>Suggested python encoding excerpted with highlights, autogenerated:<u></u><u></u></p><p><u></u> <u></u></p><p>               # […]<u></u><u></u></p><p><u></u> <u></u></p><p style="margin-left:0.5in"><span style="font-size:9pt;font-family:"Courier New";color:black">  Scene=Scene(<u style="font-family:"Courier New""></u><u style="font-family:"Courier New""></u></span></p><p style="margin-left:0.5in"><span style="font-size:9pt;font-family:"Courier New";color:black">    #  Because these NavigationInfo nodes are here in the parent scene, the first one is bound at load time, and thus governs the active navigation modes <u style="font-family:"Courier New""></u><u style="font-family:"Courier New""></u></span></p><p style="margin-left:0.5in"><span style="font-size:9pt;font-family:"Courier New";color:black">    #  Note that an author can control what choices a user has available, and initial type selected, while the user can select among navigation choices from available options <u style="font-family:"Courier New""></u><u style="font-family:"Courier New""></u></span></p><p style="margin-left:0.5in"><span style="font-size:9pt;font-family:"Courier New";color:black">    #  Author TODO: Experiment by swapping order of these NavigationInfo nodes, first one is bound at load time <u style="font-family:"Courier New""></u><u style="font-family:"Courier New""></u></span></p><p style="margin-left:0.5in"><span style="font-size:9pt;font-family:"Courier New";color:black">    children=[<u style="font-family:"Courier New""></u><u style="font-family:"Courier New""></u></span></p><p style="margin-left:0.5in"><span style="font-size:9pt;font-family:"Courier New";color:black">    WorldInfo(title='NavigationInfo.x3d'),<u style="font-family:"Courier New""></u><u style="font-family:"Courier New""></u></span></p><p style="margin-left:0.5in"><span style="font-size:9pt;font-family:"Courier New";color:black">    NavigationInfo(DEF='DEFAULT_EXAMINE_FIRST'),<u style="font-family:"Courier New""></u><u style="font-family:"Courier New""></u></span></p><p style="margin-left:0.5in"><span style="font-size:9pt;font-family:"Courier New";color:black">    NavigationInfo(DEF='FLY_FIRST',<span style="background:0% 50% repeat yellow;font-family:"Courier New"">type=</span></span><b><span style="font-size:9pt;font-family:"Courier New";background:0% 50% repeat yellow;color:rgb(237,125,49)">'"FLY" "ANY"'</span></b><span style="font-size:9pt;font-family:"Courier New";color:black">),<u style="font-family:"Courier New""></u><u style="font-family:"Courier New""></u></span></p><p style="margin-left:0.5in"><span style="font-size:9pt;font-family:"Courier New";color:black">    NavigationInfo(DEF='SIT_TIGHT',<span style="background:0% 50% repeat yellow;font-family:"Courier New"">type='"NONE"'</span>),<u style="font-family:"Courier New""></u><u style="font-family:"Courier New""></u></span></p><p style="margin-left:0.5in"><span style="font-size:9pt;font-family:"Courier New";color:black">    #  Also note that this scene does not provide a way to select a different NavigationInfo node during run time <u style="font-family:"Courier New""></u><u style="font-family:"Courier New""></u></span></p><p style="margin-left:0.5in"><span style="font-size:9pt;font-family:"Courier New";color:black">    Inline(<span style="background:0% 50% repeat yellow;font-family:"Courier New"">url=["../HelloWorld.x3d",<a href="https://www.web3d.org/x3d/content/examples/X3dForWebAuthors/HelloWorld.x3d" style="font-family:"Courier New"" target="_blank">https://www.web3d.org/x3d/content/examples/X3dForWebAuthors/HelloWorld.x3d</a>,"../HelloWorld.wrl",</span></span><b><span style="font-size:9pt;font-family:"Courier New";background:0% 50% repeat yellow;color:rgb(237,125,49)"><a href="https://www.web3d.org/x3d/content/examples/X3dForWebAuthors/HelloWorld.wrl" style="font-family:"Courier New"" target="_blank"><span style="font-family:"Courier New";color:rgb(237,125,49)">https://www.web3d.org/x3d/content/examples/X3dForWebAuthors/HelloWorld.wrl</span></a></span></b><span style="font-size:9pt;font-family:"Courier New";background:0% 50% repeat yellow;color:black">]</span><span style="font-size:9pt;font-family:"Courier New";color:black">)])<u style="font-family:"Courier New""></u><u style="font-family:"Courier New""></u></span></p><p style="margin-left:0.5in"><span style="font-size:9pt;font-family:"Courier New";color:black">) # X3D model complete<u style="font-family:"Courier New""></u><u style="font-family:"Courier New""></u></span></p><p><u></u> <u></u></p><p>Checking on compilation and execution during unit tests:<u></u><u></u></p><p><u></u> <u></u></p><ul style="margin-top:0in" type="disc"><li><a href="https://sourceforge.net/p/x3d/code/HEAD/tree/www.web3d.org/x3d/content/examples/build.python.all.log.txt" target="_blank">https://sourceforge.net/p/x3d/code/HEAD/tree/www.web3d.org/x3d/content/examples/build.python.all.log.txt</a><u></u><u></u></li></ul><p><u></u> <u></u></p><p><span style="font-size:9pt">===================================<u></u><u></u></span></p><p><span style="font-size:9pt">create python:<u></u><u></u></span></p><p><span style="font-size:9pt">C:\x3d-code\<a href="http://www.web3d.org" target="_blank">www.web3d.org</a>\x3d\content\examples\X3dForWebAuthors/Chapter04ViewingNavigation//NavigationInfoExample.x3d processing with X3dToPython stylesheet...<u></u><u></u></span></p><p><span style="font-size:9pt">C:\x3d-code\<a href="http://www.web3d.org" target="_blank">www.web3d.org</a>\x3d\content\examples\X3dForWebAuthors/Chapter04ViewingNavigation//NavigationInfoExample.py self-validation tests...<u></u><u></u></span></p><p><span style="font-size:9pt">validate python:<u></u><u></u></span></p><p><span style="font-size:9pt">x3d.py package 4.0.64.0 loaded, have fun with X3D Graphics!<u></u><u></u></span></p><p><span style="font-size:9pt">Self-test diagnostics for NavigationInfoExample.py:<u></u><u></u></span></p><p><span style="font-size:9pt">meta info: Contained Inline scene has profile Immersive<u></u><u></u></span></p><p><span style="font-size:9pt">Python-to-XML well-formed XML document  test of XML output complete<u></u><u></u></span></p><p><span style="font-size:9pt">Python-to-XML X3D 3.3 schema validation test of XML output complete<u></u><u></u></span></p><p><span style="font-size:9pt">Python-to-VRML export of VRML output successful<u></u><u></u></span></p><p><span style="font-size:9pt">Python-to-JSON export of JSON output successful (under development)<u></u><u></u></span></p><p><span style="font-size:9pt">python NavigationInfoExample.py load and self-test diagnostics complete.<u></u><u></u></span></p><p><span style="font-size:9pt">===================================<u></u><u></u></span></p><p><u></u> <u></u></p><p>However am seeing two errors:<u></u><u></u></p><p><u></u> <u></u></p><ol style="margin-top:0in" start="4" type="a"><li>Looks like the example excerpt is helpful but also has two mistakes:<u></u><u></u></li></ol><p><u></u> <u></u></p><ul style="margin-top:0in" type="disc"><li style="margin-left:0.25in"><span style="font-size:9pt;font-family:"Courier New";color:black">NavigationInfo(DEF='FLY_FIRST',<span style="background:0% 50% repeat yellow;font-family:"Courier New"">type='"FLY" "ANY"'</span>),</span><u></u><u></u></li></ul><p style="margin-left:0.75in">should be <u></u><u></u></p><ul style="margin-top:0in" type="disc"><li style="margin-left:0.25in"><span style="font-size:9pt;font-family:"Courier New";color:black">NavigationInfo(DEF='FLY_FIRST',<span style="background:0% 50% repeat aqua;font-family:"Courier New"">type=["FLY","ANY"]),</span></span><u></u><u></u></li></ul><p><u></u> <u></u></p><ul style="margin-top:0in" type="disc"><li style="margin-left:0.25in">Last value in url MFString list is <b><span style="font-size:9pt;font-family:"Courier New";color:rgb(237,125,49)">unquoted</span></b><span style="font-size:9pt;color:rgb(237,125,49)"> </span>(scroll way-way-way to the right to find it)<u></u><u></u></li></ul><p><u></u> <u></u></p><p>I will work on the <i>X3dToPython.xslt</i> conversion stylesheet to address these two conversion errors (be patient please).<u></u><u></u></p><p><u></u> <u></u></p><p>all the best, Don<u></u><u></u></p><p>-- <u></u><u></u></p><p><span style="font-size:9pt;font-family:"Courier New"">Don Brutzman  Naval Postgraduate School, Code USW/Br        <a href="mailto:brutzman@nps.edu" style="font-family:"Courier New"" target="_blank">brutzman@nps.edu</a><u style="font-family:"Courier New""></u><u style="font-family:"Courier New""></u></span></p><p><span style="font-size:9pt;font-family:"Courier New"">Watkins 270,  MOVES Institute, Monterey CA 93943-5000 USA    +1.831.656.2149<u style="font-family:"Courier New""></u><u style="font-family:"Courier New""></u></span></p><p><span style="font-size:9pt;font-family:"Courier New"">X3D graphics, virtual worlds, navy robotics <a href="https://faculty.nps.edu/brutzman" style="font-family:"Courier New"" target="_blank">https://faculty.nps.edu/brutzman</a><u style="font-family:"Courier New""></u><u style="font-family:"Courier New""></u></span></p></div></div><div lang="EN-US"><div><p><u></u> <u></u></p><p>-----Original Message-----<br>From: x3d-public <<a href="mailto:x3d-public-bounces@web3d.org" target="_blank">x3d-public-bounces@web3d.org</a>> On Behalf Of Vincent Marchetti<br>Sent: Wednesday, July 19, 2023 5:48 AM<br>To: John Carlson <<a href="mailto:yottzumm@gmail.com" target="_blank">yottzumm@gmail.com</a>>; X3D-Public <<a href="mailto:x3d-public@web3d.org" target="_blank">x3d-public@web3d.org</a>><br>Subject: Re: [x3d-public] MFString in python x3d.py</p><p><u></u> <u></u></p><p>> On Jul 19, 2023, at 5:40 AM, John Carlson <<a href="mailto:yottzumm@gmail.com" target="_blank"><span style="text-decoration:none;color:windowtext">yottzumm@gmail.com</span></a>> wrote:<u></u><u></u></p><p>> <u></u><u></u></p><p>> First off, I realize x3d.py JSON is under development.<u></u><u></u></p><p>> <u></u><u></u></p><p>> I'm trying to output an MFString to JSON in x3d.py and I'm kind of stuck?  I've been modifying x3d.py to JSON output, but I've spent way too much time on it and it's dang frustrating.<u></u><u></u></p><p>> <u></u><u></u></p><p>> I have the code:<u></u><u></u></p><p>> <u></u><u></u></p><p>> ImageTexture(url=["images/X3dJavaSceneAccessInterfaceSaiLibrary.png","<u></u><u></u></p><p>> <a href="http://www.web3d.org/specifications/java/examples/images/X3dJavaSceneA" target="_blank"><span style="text-decoration:none;color:windowtext">http://www.web3d.org/specifications/java/examples/images/X3dJavaSceneA</span></a><u></u><u></u></p><p>> ccessInterfaceSaiLibrary.png"])<u></u><u></u></p><p>> <u></u><u></u></p><p>> Don has:<u></u><u></u></p><p>> <u></u><u></u></p><p>> ImageTexture(url=["images/X3dJavaSceneAccessInterfaceSaiLibrary.png","<u></u><u></u></p><p>> <a href="http://www.web3d.org/specifications/java/examples/images/X3dJavaSceneA" target="_blank"><span style="text-decoration:none;color:windowtext">http://www.web3d.org/specifications/java/examples/images/X3dJavaSceneA</span></a><u></u><u></u></p><p>> ccessInterfaceSaiLibrary.png"])<u></u><u></u></p><p>> <u></u><u></u></p><p><u></u> <u></u></p><p>Yes, those two declarations of the ImageTexture node are the same.<u></u><u></u></p><p>Can you show what the resulting json encoding of this node is, and what problems are occurring with that encoding?<u></u><u></u></p><p><u></u> <u></u></p><p>> The same, right?<u></u><u></u></p><p>> <u></u><u></u></p><p>> I'm wondering if I should try this approach:<u></u><u></u></p><p>> <u></u><u></u></p><p>> NavigationInfo(type="\"EXAMINE\" \"FLY\" \"ANY\""),<u></u><u></u></p><p>> <u></u><u></u></p><p><u></u> <u></u></p><p>I would recommend against this.<u></u><u></u></p><p><u></u> <u></u></p><p>This approach is mixing up the details of several different encodings at once.<u></u><u></u></p><p><u></u> <u></u></p><p>The expression you have there, in particular the \" constructions, is going to be interpreted according to the rules of the Python Lexical parser <a href="https://docs.python.org/3/reference/lexical_analysis.html#string-and-bytes-literals" target="_blank">https://docs.python.org/3/reference/lexical_analysis.html#string-and-bytes-literals</a><u></u><u></u></p><p>and, if done just right, gives you the single python string with value "EXAMINE""FLY""ANY"<u></u><u></u></p><p>This string only works as to represent an MFString value, when used to form an XML attribute in the XML encoding of X3D. It has little to do with json.<u></u><u></u></p><p><u></u> <u></u></p><p>> John<u></u><u></u></p><p>> <u></u><u></u></p><p><u></u> <u></u></p><p>Vince Marchetti<u></u><u></u></p></div></div><div lang="EN-US"><div><p>_______________________________________________<u></u><u></u></p><p>x3d-public mailing list<u></u><u></u></p><p><a href="mailto:x3d-public@web3d.org" target="_blank"><span style="text-decoration:none;color:windowtext">x3d-public@web3d.org</span></a><u></u><u></u></p><p><a href="http://web3d.org/mailman/listinfo/x3d-public_web3d.org" target="_blank"><span style="text-decoration:none;color:windowtext">http://web3d.org/mailman/listinfo/x3d-public_web3d.org</span></a><u></u><u></u></p></div></div></blockquote></div></div>
</blockquote></div>