[x3d-public] X3DJSAIL progress report: quote escapinig, node validation, .jsonimprovements, containerField handling

Don Brutzman brutzman at nps.edu
Mon Mar 20 22:15:48 PDT 2017


On 3/20/2017 5:59 PM, yottzumm at gmail.com wrote:
> Is there some configuration setting for quoting in the X3dToJson.xslt stylesheet?

No, it should be explicit with no variations.

If you want to check for parameters and default settings in the future, here is parameter list at top of that stylesheet:

<xsl:stylesheet version="2.0" exclude-result-prefixes="ds saxon"
                 xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
                 xmlns:ds="http://www.w3.org/2000/09/xmldsig#"
                 xmlns:saxon="http://icl.com/saxon" saxon:trace="no">
     <!--
                 xmlns="http://www.w3.org/TR/xhtml1/strict"
                 xmlns:fn="http://www.w3.org/2005/xpath-functions" -->
                 
     <xsl:param name="stripComments"><xsl:text>false</xsl:text></xsl:param>
     <xsl:param name="stripDefaultAttributes"><xsl:text>true</xsl:text></xsl:param>
     <xsl:param name="indentEnabled"><xsl:text>true</xsl:text></xsl:param>
     <xsl:param name="sourceText"><xsl:text>strings</xsl:text></xsl:param> <!-- escaped | strings | plaintext -->
     <xsl:param name="traceEnabled" ><xsl:text>false</xsl:text></xsl:param>
     <xsl:param name="traceScripts" ><xsl:text>false</xsl:text></xsl:param>
	<!-- TODO future feature: whether to apply changes to meta references, url file extensions, etc. -->
     <xsl:param name="updateContent" ><xsl:text>false</xsl:text></xsl:param>

>   See differences between text.json and text.new.json (Search for string starting with Node.

I think that the conversion from XML .x3d to .json has to backslash-escape the contained \ and " characters independently.

In other words, \ becomes \\ and " becomes \"

Hence for examples

	http://www.web3d.org/specifications/java/X3DJSAIL.html#Examples
	http://www.web3d.org/specifications/java/examples/HelloWorldProgramOutput.x3d
	http://www.web3d.org/specifications/java/examples/HelloWorldProgramOutput.json

you find the following correspondence:

<MetadataString name='escapedQuotesTest1' containerField='value' value='"escaped quotation marks example 1: He said, \"Immel did it!\""'/>

{ "MetadataString":
   {
	"@name":"escapedQuotesTest1",
	"@value":["escaped quotation marks example 1: He said, \\\"Immel did it!\\\""]
   }
},

Of course, escaping is especially important in <Text> nodes, where the author might want quote marks in the X3D string that the user sees.

Not sure whatever it was we had before, but it would seem this is the correct answer now.  Hope you will agree.

Good to confirm: can you round-trip the .json back to .x3d XML?


> John
>
>
>
> Sent from Mail <https://go.microsoft.com/fwlink/?LinkId=550986> for Windows 10
>
>
>
> *From: *Don Brutzman <mailto:brutzman at nps.edu>
> *Sent: *Sunday, March 19, 2017 5:24 PM
> *To: *X3D Graphics public mailing list <mailto:x3d-public at web3d.org>
> *Cc: *Roy Walmsley <mailto:roy.walmsley at ntlworld.com>; John Carlson <mailto:yottzumm at gmail.com>
> *Subject: *Re: X3DJSAIL progress report: quote escapinig, node validation, .jsonimprovements, containerField handling
>
>
>
> Further updates now deployed:
>
>
>
> - A  bunch of work for escaping quotes in the X3dToJson.xslt stylesheet
>
> - Improved handling of quotation marks and escaping
>
> - Validating acceptableNodeTypes for setting nodes
>
>
>
> Now handling most (perhaps all?) containerField values OK.  Related documentation now available at
>
>
>
> http://www.web3d.org/x3d/content/examples/X3dSceneAuthoringHints.html#containerField
>
> ========================================================================
>
> X3D Scene Authoring Hints: containerField
>
>
>
>>  For the XML encoding of .x3d scenes, containerField is the field name indicating a node's field relationship to its parent node.
>
>>
>
>> For example: <Transform><Shape containerField='children'/></Transform> shows that the Shape node is one of the children of the Transform node.
>
>>
>
>>     Default containerField values for each node are correct in most cases, so the need to override default containerField values is rare.
>
>>     Example values include containerField='geometry' for Box node, containerField='children' for Group node, containerField='proxy' for hidden proxy shape within a Collision node, etc.
>
>>     containerField attribute is part of XML encoding for X3D scenes, and corresponds to the always-declared field labels in the ClassicVRML and VRML97 file encodings.
>
>>
>
>> A small number of nodes have more than one field that can accept the same node type. Care must be taken with the following non-default child fields.
>
>>
>
>>     MetadataSet can have a single X3DMetadataNode node with default containerField='metadata', or multiple other X3DMetadataNode nodes with containerField='value'.
>
>>     CADFace and CollidableShape can have a single default Shape node with containerField='shape'. CADFace can also accept an LOD or Transform node in this SFNode field.
>
>>     Collision can contain multiple nodes with default containerField='children', or can have a single unrendered Shape, or X3DGroupingNode with containerField='proxy'.
>
>
>
> ========================================================================
>
>
>
> Also rebuilt and uploaded all .json scenes in X3D Examples, see "Special testing distribution" at
>
>
>
>                 http://www.web3d.org/x3d/content/examples/X3dResources.html#Examples
>
>
>
> Test excerpts follow, linked at
>
>
>
>                 X3DJSAIL Examples
>
>                 http://www.web3d.org/specifications/java/X3DJSAIL.html#Examples
>
>
>
> http://www.web3d.org/specifications/java/examples/HelloWorldProgramOutput.txt
>
> ========================================================================
>
> <Shape>
>
>                 <Appearance>
>
>                                 <Material/>
>
>                 </Appearance>
>
>                 <Text string='"X3D Java" "SAI Library" "X3DJSAIL"'>
>
>                                 <MetadataSet name='EscapedQuotationMarksMetadataSet'>
>
>                                                 <MetadataString name='escapedQuotesTest2' value='"escaped quotation marks example 2: He said, \"Immel did it!\""'/>
>
>                                 </MetadataSet>
>
>                                 <FontStyle family='"SERIF"' justify='"MIDDLE" "MIDDLE"'/>
>
>                                 <!-- escaped quotation marks example 3: He said, \"Immel did it!\" -->
>
>                                 <!-- escaped quotation marks example 4: He said, \"Immel did it!\" -->
>
>                 </Text>
>
> </Shape>
>
> <Collision>
>
>                 <!-- test containerField='proxy' -->
>
>                 <Shape DEF='ProxyShape'>
>
>                                 <Box/>
>
>                 </Shape>
>
> </Collision>
>
> ========================================================================
>
> { "Shape":
>
>    {
>
>                 "-appearance":
>
>                   { "Appearance":
>
>                                 {
>
>                                   "-material":
>
>                                                 { "Material":
>
>                                                   {
>
>                                                   }
>
>                                                 }
>
>                                 }
>
>                   },
>
>                 "-geometry":
>
>                   { "Text":
>
>                                 {
>
>                                   "@string":["X3D Java","SAI Library","X3DJSAIL"],
>
>                                   "-metadata":
>
>                                                 { "MetadataSet":
>
>                                                   {
>
>                                                                 "@name":"EscapedQuotationMarksMetadataSet",
>
>                                                                 "-value":[
>
>                                                                   { "MetadataString":
>
>                                                                                 {
>
>                                                                                   "@name":"escapedQuotesTest1",
>
>                                                                                   "@value":["escaped quotation marks example 1: He said, \\\"Immel did it!\\\""]
>
>                                                                                 }
>
>                                                                   },
>
>                                                                   { "MetadataString":
>
>                                                                                 {
>
>                                                                                   "@name":"escapedQuotesTest2",
>
>                                                                                   "@value":["escaped quotation marks example 2: He said, \\\"Immel did it!\\\""]
>
>                                                                                 }
>
>                                                                   }
>
>                                                                 ]
>
>                                                   }
>
>                                                 },
>
>                                   "-fontStyle":
>
>                                                 { "FontStyle":
>
>                                                   {
>
>                                                                 "@justify":["MIDDLE","MIDDLE"]
>
>                                                   }
>
>                                                 },
>
>                                   "-children":[
>
>                                                 {
>
>                                                   "#comment":"escaped quotation marks example 3: He said, \\\"Immel did it!\\\""
>
>                                                 },
>
>                                                 {
>
>                                                   "#comment":"escaped quotation marks example 4: He said, \\"Immel did it!\\""
>
>                                                 }
>
>                                   ]
>
>                                 }
>
>                   }
>
>    }
>
> },
>
> { "Collision":
>
>    {
>
>                 "-children":[
>
>                   {
>
>                                 "#comment":"test containerField='proxy'"
>
>                   }
>
>                 ],
>
>                 "-proxy":
>
>                   { "Shape":
>
>                                 {
>
>                                   "@DEF":"ProxyShape",
>
>                                   "-geometry":
>
>                                                 { "Box":
>
>                                                   {
>
>                                                   }
>
>                                                 }
>
>                                 }
>
>                   }
>
>    }
>
> },
>
> ========================================================================
>
>
>
> On 3/13/2017 8:38 AM, Don Brutzman wrote:
>
>> A new X3DLoaderObject is now ready that can read .x3d scenes using native Java DOM support, using Java Reflection to then create strongly typed X3DJSAIL scene objects.  Online at
>
>>
>
>>     X3DLoaderObject: Concrete class for loading an X3D graphics string, file or fragment encoded in XML.
>
>>     http://www.web3d.org/specifications/java//javadoc/org/web3d/x3d/jsail/X3DLoaderObject.html
>
>>
>
>> with methods
>
>>     getDomDocument() isLoadSuccessful() getValidationResult() getX3dObjectTree()
>
>>     loadX3DfromFile(x3dFile) toStringX3D(org.w3c.dom.Node node) toX3dObjectTree(org.w3c.dom.Node node)
>
>>
>
>> Example result
>
>>     https://svn.code.sf.net/p/x3d/code/www.web3d.org/x3d/stylesheets/java/examples/HelloWorldProgramOutput.Reloaded.x3d
>
>>
>
>> which is a reloaded and serialized output that exactly matches input scene
>
>>     https://svn.code.sf.net/p/x3d/code/www.web3d.org/x3d/stylesheets/java/examples/HelloWorldProgramOutput.x3d
>
>>
>
>> This library improvement fixes a significant bug in field types, which are getting more robust.  Also add a variety of .normalize() utility methods and validation checks on negative SFTime/MFTime values.
>
>>     http://www.web3d.org/specifications/java/javadoc/org/web3d/x3d/jsail/fields/MFColorObject.html
>
>>
>
>> As ever, demonstration test source available in
>
>>     http://www.web3d.org/specifications/java/examples/HelloWorldProgram.java
>
>>
>
>> Entire build online via
>
>>     http://www.web3d.org/specifications/java/X3DJSAIL.html
>
>
>
> Have fun with X3D Java using X3DJSAIL!  8)
>
>
>
> 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
>
>
>


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



More information about the x3d-public mailing list