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

Don Brutzman brutzman at nps.edu
Tue Mar 21 00:32:02 PDT 2017


On 3/20/2017 11:12 PM, yottzumm at gmail.com wrote:
> Comments embedded.
>
>>   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 \"
>
>
>
> Yes, but what does \" become  \\\" or \"?

\" become  \\\" (each character gets escaped, one at a time)

>   What do I do for the Java?  You would think I have an extra \ or something.

going from source to Java, you can escape each \ individually.  However you have to parse the MFString, or perform other string trickery, to figure out if a " character is delimiting an SFString value in the MFString array or contained content.

Suggestion: since any embedded " within an SFSTring value should be represented as \", handle (or protect) those as a a pair before splitting MFString into separate SFString values.

> Hence for examples
> [...]
>
> That’s text.x3d.new.  It’s WAY different.  Looks like
>
> <Text containerField="geometry" string=""Node\\\"\\\"\\\""">

Note that your string="(blah)" value has outer quotation marks, which forces all contained quotation marks " to be escaped using XML character entities as " values.  Plus each \ gets escaped as \\ and the & in " gets escaped as \"....

dizzy yet?!  this is why i prefer delimiting attributes with apostrophes, string='(blah)' is much simpler.

> Please check text.java for correctness.  I’m not too sure about all this…

your text.java
	.setString(new String[] {"Node\\\"\\\"\\\""})

should match

	<Text string='Node\"\"\"'/>

yes indeed tricky.  but doable, and we only have to get it right once...

>   Seems like one X3dToJson.xslt run (text.x3d -> text.json) should be the same as another (text.json.intermediate.x3d -> text.new.json).  I can regen if you think it’s best.  The two X3D files are nearly identical.  Is it possible I am using two different style sheets?  text.json was translated today.
>
>
>
> I figured it out.  I am using two different versions of the XSLT stylesheet jar.  One must be wrong.  Which is it?  RunSaxon.java (same as x3d resource examples I think) uses saxon9B.jar which is old.  So the original text.json is incorrect?  Please check.  Seems like I’m going to have to upgrade RunSaxon.java to the latest release (which do you recommend?).  How would I translate this Java code to the new form?

i am using saxon unrestricted version saxon9he.jar (home edition) which is bundeled in the lib directory of the X3DJSAIL jars.

>                                         net.sf.saxon.Transform.main(new String[] {
>
>                                                                 "-warnings:recover",
>
>                                                                 "-o",
>
>                                                                 out,
>
>                                                                 args[a],
>
>                                                                 "X3dToJson.xslt" });
>
>
>
> I think we have a major conflict within one stylesheet vendor, or between stylesheet vendors.  Help!
>
> I use:
>
> ConfigurationProperties.setXsltEngine(ConfigurationProperties.XSLT_ENGINE_nativeJava);
>
> In my Java to generate JSON.  What do you recommend?  I think we need to file a bug report with someone!  Please text all my X3D files for conversion to JSON with various stylesheet jar vendors!

i recommend that you use the bundled version from saxon, i have found saxon to be most reliable/compliant.  we can test the java support (which likely varies across java versions) at a future time.

Thanks for trudging forward John, it is indeed a tricky business.

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