[x3d-public] JSON encoding of unexpected additional attributes on Scene, head, ProtoBody and IS elements

Don Brutzman brutzman at nps.edu
Fri Nov 27 11:28:58 PST 2015


OK then.. I was able to get the converter to be tolerant of unexpected attributes.  That is good news, our design pattern looks OK.  Also very important for HTML/DOM authors who might attach such attributes with reckless abandon!

Temporary test-case conversion attached (note DEF on the Scene element) and stylesheet update is checked in.  Again thanks for identifying this issue.

On 11/27/2015 10:56 AM, Don Brutzman wrote:
> Thanks for the further dialog on the conversion issue.
>
> I will work on whether the X3dToJson.xslt stylesheet can be more tolerant when it encounters unexpected attributes.  The result might not be valid X3D, but at least it will be valid JSON.  This is important for supporting experimentation.
>
> Hopefully the JSON pattern we have established won't need modification...
>
> On 11/25/2015 5:11 PM, Don Brutzman wrote:
>> Hi John.  I checked and tested a number of scenes, the Scene tag looks OK and they are all continuing to pass without throwing jslint errors.
>>
>> I believe that the problem is in your Scene tag, it is not supposed to have attributes.  There are no corrolaries for those in other encodings.  Though I suppose we might well expect to have them since a <Scene> element might get decorated with attributes by DOM operations or other editing.
>>
>> Similar situation exists for elements head, Scene, ProtoBody and IS.  The current encoding treats those as containing simple objects rather than containing an array.
>>
>> I recommend taking the attribute off of Scene (if possible) so that you can proceed, and we think about this some more.  Am hesitant before opening a door that might encourage otherwise-invalid X3D content.
>
> ============================================
>
> On 11/25/2015 3:07 PM, John Carlson wrote:
>> Don, the stylesheet in X3D-Edit and the one I downloaded from here http://www.web3d.org/x3d/stylesheets/ <http://www.web3d.org/x3d/stylesheets/>*X3dToJson*.*xslt both produce this JSON which has a bad Scene object.*
>> *
>> *Note the object which is used as a key in the Scene:*
>> *
>> *“Scene”: { {*
>> *
>> *The second brace is illegal.  Please get a JSON parser or jsonlint-lines and use it.  Original X3D is include below:*
>> *
>> *John*
>>
>>
>> { "X3D": {
>>      "@id":"x3dElement",
>>      "@showStat":false,
>>      "@showLog":false,
>>      "@style":"width:100%; height:100%; border:0; margin:0; padding:0;",
>>      "@xsd:noNamespaceSchemaLocation":"http://www.web3d.org/specifications/x3d-3.3.xsd",
>
> here was the problem, double braces, caused by translator confusion at having a DEF attribute appear as part of Scene.
>
>>      "Scene": {
>>        {
>>          "@DEF":"scene",
>>          "-children":[
>
>
> all the best, Don


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
-------------- next part --------------
A non-text attachment was scrubbed...
Name: TestJsonEncoding.x3d
Type: model/x3d+xml
Size: 2877 bytes
Desc: not available
URL: <http://web3d.org/pipermail/x3d-public_web3d.org/attachments/20151127/8767f585/attachment.x3d>
-------------- next part --------------
{ "X3D": {
    "@profile":"Immersive",
    "@version":3.3,
    "@xsd:noNamespaceSchemaLocation":"http://www.web3d.org/specifications/x3d-3.3.xsd",
    "head": {
        "component": [
          {
            "@name":"CADGeometry",
            "@level":1
          },
          {
            "@name":"H-Anim",
            "@level":1
          }
        ],
        "unit": [
          {
            "@name":"Yards",
            "@category":"length",
            "@conversionFactor":0.9144
          },
          {
            "@name":"Degrees",
            "@category":"angle",
            "@conversionFactor":0.0174532925167
          }
        ],
        "meta": [
          {
            "@name":"title",
            "@content":"TestJsonEncoding.x3d"
          },
          {
            "@name":"creator",
            "@content":"Don Brutzman"
          },
          {
            "@name":"created",
            "@content":"29 March 2015"
          },
          {
            "@name":"modified",
            "@content":"3 November 2015"
          },
          {
            "@name":"description",
            "@content":"Test scene to ensure that X3dToJson xslt stylesheet translator properly converts X3D source into JavaScript Object Notation (JSON)."
          },
          {
            "@name":"reference",
            "@content":"TestJsonEncoding.json"
          },
          {
            "@name":"reference",
            "@content":"http://www.web3d.org/wiki/index.php/X3D_JSON_Encoding"
          },
          {
            "@name":"identifier",
            "@content":"http://www.web3d.org/x3d/content/examples/Basic/development/TestJsonEncoding.x3d"
          },
          {
            "@name":"reference",
            "@content":"http://www.web3d.org/x3d/stylesheets/X3dToJson.xslt"
          },
          {
            "@name":"reference",
            "@content":"http://www.web3d.org/x3d/stylesheets/X3dToJson.html"
          },
          {
            "@name":"generator",
            "@content":"X3D-Edit 3.3, https://savage.nps.edu/X3D-Edit"
          },
          {
            "@name":"license",
            "@content":"../license.html"
          }
        ]
    },
    "Scene":
      {
        "@DEF":"ExtraneousInvalidAttribute",
        "#comment":[
          "excerpted from HelloWorld.x3d"
        ],
        "-children":[
          { "Group":
            {
              "-children":[
                { "Viewpoint":
                  {
                    "@DEF":"ViewUpClose",
                    "@centerOfRotation":[0,-1,0],
                    "@description":"Hello world!",
                    "@position":[0,-1,7]
                  }
                },
                { "Transform":
                  {
                    "@rotation":[0,1,0,3],
                    "-children":[
                      { "Shape":
                        {
                          "-geometry":[
                            { "Sphere":
                              {
                              }
                            }
                          ],
                          "-appearance":[
                            { "Appearance":
                              {
                                "#comment":[
                                  "Test leading zeroes inserted before (and trailing zeroes inserted after) decimal points: diffuseColor='.1 0.5 1.'"
                                ],
                                "-material":[
                                  { "Material":
                                    {
                                      "@DEF":"MaterialLightBlue",
                                      "@diffuseColor":[0.1,0.5,1.0]
                                    }
                                  }
                                ],
                                "-texture":[
                                  { "ImageTexture":
                                    {
                                      "@DEF":"ImageCloudlessEarth",
                                      "@url":["earth-topo.png","earth-topo.jpg","earth-topo-small.gif","http://www.web3d.org/x3d/content/examples/Basic/earth-topo.png","http://www.web3d.org/x3d/content/examples/Basic/earth-topo.jpg","http://www.web3d.org/x3d/content/examples/Basic/earth-topo-small.gif"]
                                    }
                                  }
                                ]
                              }
                            }
                          ]
                        }
                      }
                    ]
                  }
                },
                { "Transform":
                  {
                    "@translation":[-0.1,-2,-0.2],
                    "#comment":[
                      "Test leading zeroes inserted between -. values: translation='-.1 -2 -.2'"
                    ],
                    "-children":[
                      { "Shape":
                        {
                          "-geometry":[
                            { "Text":
                              {
                                "@DEF":"TextMessage",
                                "@string":["Hello","JSON!"],
                                "-fontStyle":[
                                  { "FontStyle":
                                    {
                                      "@justify":["MIDDLE","MIDDLE"]
                                    }
                                  }
                                ]
                              }
                            }
                          ],
                          "-appearance":[
                            { "Appearance":
                              {
                                "-material":[
                                  { "Material":
                                    {
                                      "@USE":"MaterialLightBlue"
                                    }
                                  }
                                ]
                              }
                            }
                          ]
                        }
                      }
                    ]
                  }
                }
              ]
            }
          }
        ]
      }
  }
}


More information about the x3d-public mailing list