[X3D-Public] [x3dom-developers] initial X3D JSON conversion support using X3dToJson.xslt

Don Brutzman brutzman at nps.edu
Sun Oct 12 09:27:12 PDT 2014


Further progress:  working satisfactorily, examples attached.

Details during latest iteration:
- figured out how to invoke saxon as xslt invocation in ant for suppression of default attribute values
   inserted by XML parser reading DOCTYPE
     http://stackoverflow.com/questions/11749319/how-can-i-ignore-the-doctype-declaration-with-xsl
     Saxon command-line option expand:off
     http://saxonica.com/documentation9.0/using-xsl/commandline.html
- tested handling of single number, e.g. "@transparency": 0.1

=======================================================================
X3dToJson.xslt Conversion Status

1. Working:
- elements, attributes, comments
- Square and squiggly brackets, commas
- escaping quotation marks
- handling of singleton numeric values, e.g.
	"transparency": [1],
or
	"transparency": 1,
- suppression of default attribute values inserted by XML parser reading DOCTYPE
     http://stackoverflow.com/questions/11749319/how-can-i-ignore-the-doctype-declaration-with-xsl
     Saxon command-line option expand:off
     http://saxonica.com/documentation9.0/using-xsl/commandline.html

2. TODO
- strictly differentiate typing of string versus number versus boolean values and arrays
     (currently done heuristically)
- handling of MFVec arrays, for example
	"keyValue": [0, 0, 0, 1, 1, 1, 2, 2, 2],
or
	"keyValue": [ [0, 0, 0], [1, 1, 1], [2, 2, 2] ],
- handling special characters in strings
- contained CDATA text (for example, contained Script source code)
- round-trip testing using a JSON-to-XML converter
- embedded support in X3D-Edit

3. What X3D JSON specification will need to specify:

- @attributeName
- "#comment"
- "#CDATA'
- handling of values and arrays for numeric, boolean and string types
- use of "null" (if any)
- handling of MFVec arrays
- omitting default attribute values and default containerField values

4. Apparently  not possible:
- embedded JSON comments disallowed
     http://www.quora.com/How-do-I-write-comments-inside-a-JSON-document
=======================================================================

Latest results maintained at
  
https://svn.code.sf.net/p/x3d/code/www.web3d.org/x3d/stylesheets/X3dToJson.xslt
https://svn.code.sf.net/p/x3d/code/www.web3d.org/x3d/stylesheets/build.xml (target test.X3dToJson.xslt)

https://svn.code.sf.net/p/x3d/code/www.web3d.org/x3d/stylesheets/test/HelloWorld.json
https://svn.code.sf.net/p/x3d/code/www.web3d.org/x3d/stylesheets/test/HelloWorld.scene.json

The json source files pass Netbeans/X3D-Edit JSON syntax testing.
  
As before, clean (unedited) versions of .json results are attached to allow testing by anyone who wants to use JSON.parse() to read and generate objects.

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 --------------
{
  "X3D": [
  {
    "@profile": "Immersive",
    "@version": 3.3,
    "@xsd:noNamespaceSchemaLocation": "http://www.web3d.org/specifications/x3d-3.3.xsd",
    "head": [
    {
      "meta": {
        "@content": "HelloWorld.x3d",
        "@name": "title"
      },
      "meta": {
        "@content": "Simple X3D example: Hello World!",
        "@name": "description"
      },
      "meta": {
        "@content": "30 October 2000",
        "@name": "created"
      },
      "meta": {
        "@content": "12 October 2014",
        "@name": "modified"
      },
      "meta": {
        "@content": "Don Brutzman",
        "@name": "creator"
      },
      "meta": {
        "@content": "HelloWorld.tall.png",
        "@name": "Image"
      },
      "meta": {
        "@content": "http://en.wikipedia.org/wiki/Hello_world",
        "@name": "reference"
      },
      "meta": {
        "@content": "http://en.wikibooks.org/w/index.php?title=Computer_Programming/Hello_world",
        "@name": "reference"
      },
      "meta": {
        "@content": "http://www.HelloWorldExample.net",
        "@name": "reference"
      },
      "meta": {
        "@content": "http://www.web3D.org",
        "@name": "reference"
      },
      "meta": {
        "@content": "http://www.web3d.org/realtime-3d/news/internationalization-x3d",
        "@name": "reference"
      },
      "meta": {
        "@content": "http://www.web3d.org/x3d/content/examples/HelloWorld.x3d",
        "@name": "reference"
      },
      "meta": {
        "@content": "http://X3dGraphics.com/examples/X3dForAdvancedModeling/HelloWorldScenes",
        "@name": "reference"
      },
      "meta": {
        "@content": "http://X3dGraphics.com/examples/X3dForWebAuthors/Chapter01-TechnicalOverview/HelloWorld.x3d",
        "@name": "identifier"
      },
      "meta": {
        "@content": "http://www.web3d.org/x3d/content/examples/license.html",
        "@name": "license"
      },
      "meta": {
        "@content": "X3D-Edit 3.3, https://savage.nps.edu/X3D-Edit",
        "@name": "generator"
      },
      "#comment": "Alternate encodings: VRML97, X3D ClassicVRML Encoding, X3D Compressed Binary Encoding (CBE), X3DOM",
      "meta": {
        "@content": "HelloWorld.wrl",
        "@name": "reference"
      },
      "meta": {
        "@content": "HelloWorld.x3dv",
        "@name": "reference"
      },
      "meta": {
        "@content": "HelloWorld.x3db",
        "@name": "reference"
      },
      "meta": {
        "@content": "HelloWorld.xhtml",
        "@name": "reference"
      }
    }
    ],
    "Scene": [
    {
      "#comment": "Example scene to illustrate X3D nodes and fields (XML elements and attributes)",
      "Group": [
      {
        "Viewpoint": {
          "@DEF": "ViewUpClose",
          "@centerOfRotation": [ 0, -1, 0 ],
          "@description": "Hello world!",
          "@position": [ 0, -1, 7 ]
        },
        "Transform": [
        {
          "@rotation": [ 0, 1, 0, 3 ],
          "Shape": [
          {
            "Sphere": {
            },
            "Appearance": [
            {
              "#comment": "added transparency value to test JSON conversion of single number",
              "Material": {
                "@DEF": "MaterialLightBlue",
                "@diffuseColor": [ 0.1, 0.5, 1 ],
                "@transparency": 0.1
              },
              "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, -2, 0 ],
          "Shape": [
          {
            "Text": [
            {
              "@DEF": "TextMessage",
              "@string": [ "Hello", "world!" ],
              "FontStyle": {
                "@justify": [ "MIDDLE", "MIDDLE" ]
              }
            }
            ],
            "Appearance": [
            {
              "Material": {
                "@USE": "MaterialLightBlue"
              }
            }
            ]
          }
          ]
        }
        ]
      }
      ]
    }
    ]
  }
  ]
}
-------------- next part --------------
{
  "#comment": "Example scene to illustrate X3D nodes and fields (XML elements and attributes)",
  "Group": [
  {
    "Viewpoint": {
      "@DEF": "ViewUpClose",
      "@centerOfRotation": [ 0, -1, 0 ],
      "@description": "Hello world!",
      "@position": [ 0, -1, 7 ]
    },
    "Transform": [
    {
      "@rotation": [ 0, 1, 0, 3 ],
      "Shape": [
      {
        "Sphere": {
        },
        "Appearance": [
        {
          "#comment": "added transparency value to test JSON conversion of single number",
          "Material": {
            "@DEF": "MaterialLightBlue",
            "@diffuseColor": [ 0.1, 0.5, 1 ],
            "@transparency": 0.1
          },
          "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, -2, 0 ],
      "Shape": [
      {
        "Text": [
        {
          "@DEF": "TextMessage",
          "@string": [ "Hello", "world!" ],
          "FontStyle": {
            "@justify": [ "MIDDLE", "MIDDLE" ]
          }
        }
        ],
        "Appearance": [
        {
          "Material": {
            "@USE": "MaterialLightBlue"
          }
        }
        ]
      }
      ]
    }
    ]
  }
  ]
}
-------------- next part --------------
A non-text attachment was scrubbed...
Name: HelloWorld.x3d
Type: model/x3d+xml
Size: 3173 bytes
Desc: not available
URL: <http://web3d.org/pipermail/x3d-public_web3d.org/attachments/20141012/e56e7ff3/attachment-0001.x3d>


More information about the X3D-Public mailing list