[x3d-public] Fwd: Encoding of MFString fields in JSON (.x3dj)

John Carlson yottzumm at gmail.com
Thu Sep 14 22:38:53 PDT 2023


Holger, this message ended up in my spam folder, but I happened to see it.

Don has announced that many MFStrings should be arrays in JSON, but he has
not spoken yet about NavigationInfo at type, he's pointed at web pages, but
that's kind of empty, see further below.

I found this fix to X3DJSONLD.java useful, but I'm converting to DOM/XML
from JSON:

        public String NavigationInfoTypeToXML(String str) {
                String y = str;
                System.err.println("X3DJSONLD jsonstring replacing "+ y);
                str = y.replaceAll("\\\\", "");
                if (!y.equals(str)) {
                        System.err.println("with
 "+ str);
                } else {
                        System.err.println("ok");
                }
                return str;
        }


                        } else if (ok instanceof JsonString) {
                                if (key.equals("#comment")) {
                                        Comment comment =
document.createComment(CommentStringToXML(ok.toString()));
                                        child.appendChild(comment);
                                } else if (key.equals("@type") &&
parentkey.equals("NavigationInfo")) {
                                        elementSetAttribute(child,
key.substring(1), NavigationInfoTypeToXML(ok.toString()));
                                } else {
                                        // ordinary string attributes
                                        elementSetAttribute(child,
key.substring(1), ok.toString());
                                }
===============================================================
I don't see a problem with X3DJSONLD.js DOM XML dump output.  See
X3DJSONLD/src/main/data/*.x3d.new


===============================================================

The pages Don listed recently showed NavigationInfo at type as an array, see:

X3D to JSON Stylesheet Converter (web3d.org)
<https://www.web3d.org/x3d/stylesheets/X3dToJson.html>

(Search for NavigationInfo)

But whether X3dToJson.xslt actually follows these rules, I would say,
"No!"  But I didn't download the stylesheet from the website!

Here are the difference in my current copy, local, then the web version:

$ diff X3dToJson.xslt ~/Downloads/X3dToJson\ \(3\).xslt
3068c3068
<                       not((local-name()='containerField' and
string(.)='texture')          and (local-name(..)='ImageTexture' or
local-name(..)='PixelTexture' or local-name(..)='MovieTexture' or
local-name(..)='MultiTexture' or local-name(..)='ComposedTexture3D' or
local-name(..)='ImageTexture3D' or local-name(..)='PixelTexture3D' or
local-name(..)='GeneratedCubeMapTexture')) and
---
>                       not((local-name()='containerField' and
string(.)='texture')          and (local-name(..)='ImageTexture' or
local-name(..)='PixelTexture' or local-name(..)='MovieTexture' or
local-name(..)='MultiTexture' or local-name(..)='ComposedTexture3D' or
local-name(..)='ImageTexture3D' or local-name(..)='PixelTexture3D')) and

Here's a recently converted file:

-rw-r--r-- 1 john 197609    14887 Sep 15 00:15 ball.json
-rw-r--r-- 1 john 197609     7774 Sep 15 00:15 ball.x3d

$ grep XAMINE ball.json
              "@type":"\"ANY\" \"EXAMINE\" \"FLY\" \"LOOKAT\""

Apparently, X3dToJson.xslt is not following what's announced on the web
pages.  No, I'm not going to take a snapshot.

$ diff X3dToJson.xslt /c/x3d-code/
www.web3d.org/x3d/stylesheets/X3dToJson.xslt

$ ls -l X3dToJson.xslt /c/x3d-code/
www.web3d.org/x3d/stylesheets/X3dToJson.xslt
-rw-r--r-- 1 john 197609 313307 Sep 14 11:52 /c/x3d-code/
www.web3d.org/x3d/stylesheets/X3dToJson.xslt
-rw-r--r-- 1 john 197609 313307 Sep 14 11:52 X3dToJson.xslt

John

---------- Forwarded message ---------
From: Holger Seelig <holger.seelig at yahoo.de>
Date: Mon, Aug 28, 2023 at 9:38 AM
Subject: [x3d-public] Encoding of MFString fields in JSON (.x3dj)
To: X3D <x3d-public at web3d.org>


There is currently an open issue about JSON encoding of MFString fields,
especially the NavigationInfo.type field:
https://github.com/create3000/x_ite/issues/146

All MFString fields should be encoded the same way: as you can see in
https://www.web3d.org/x3d/content/examples/ConformanceNist/BindableNodes/NavigationInfo/speed_scaling.json
ImageTexture and Script.url fields are encoded as JSON Array of Strings,
but NavigationInfo.type is encoded as simple string with strange contents:
https://www.web3d.org/x3d/content/examples/ConformanceNist/BindableNodes/NavigationInfo/any_type.json
.

No professional programmer would seriously use another encoding for
NavigationInfo.type, then the other MFString values have. The encoding used
for NavigationInfo.type is only useful if you are going to convert the JSON
to XML, which is probably not what you want when you parse a JSON. An Array
of String follows the same encoding scheme as the other types like MFInt32
(Array of Integers), which is very convenient.

I don't really like to change anything about the encoding of JSON in X_ITE.

Best regards,
Holger

--
Holger Seelig
Leipzig, Germany

holger.seelig at yahoo.de
https://create3000.github.io/x_ite/

_______________________________________________
x3d-public mailing list
x3d-public at web3d.org
http://web3d.org/mailman/listinfo/x3d-public_web3d.org
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://web3d.org/pipermail/x3d-public_web3d.org/attachments/20230915/050a3c08/attachment.html>


More information about the x3d-public mailing list