[x3d-public] X3dToJson.xslt vs DOM2JSONSerializer.js

John Carlson yottzumm at gmail.com
Fri May 8 03:21:43 PDT 2020


Here's critical code piece.  I know the recursive calls are the problem.
Would you suggest some kind of symbol table?

Thanks!

John

descendAttribute: function(element, at, parent, mapToMethod) {
console.log("descend attribute", element.nodeName, at)
var value = "";
if (at === "containerField") {
value = "children";
}
if (element !== null && typeof element !== 'undefined') {
for (var a in element.attributes) {
var attrs = element.attributes;
try {
parseInt(a);
if (attrs.hasOwnProperty(a) && attrs[a].nodeType == 2) {
var attr = attrs[a].nodeName;
if (attr === at) {
value = attrs[a].nodeValue;
}
if (attr === 'name') {
var fieldName = attrs[a].nodeValue;
}
}
} catch (e) {
console.error(e);
}
}
// find the value of to Proto field's type
if (element.parentNode) {
var parentName = this.descendAttribute(element.parentNode, "name");
// console.error("parent", parentName, "DEF", def, "fieldName", fieldName,
element.parentNode);
var def = this.descendAttribute(element.parentNode, "DEF");
if (element.nodeName === "field" && at === 'type') {
if (element.parentNode.nodeName === "ExternProtoDeclare" ||
   element.parentNode.parentNode.nodeName === "ProtoDeclare") {
if (!parentName) {
parentName = this.descendAttribute(element.parentNode.parentNode, "name");
}
if (typeof def === 'undefined') {
def = this.descendAttribute(element.parentNode.parentNode, "DEF");
}
if (typeof parentName !== 'undefined') {
if (typeof this.fieldTypeMapping[parentName] === 'undefined') {
this.fieldTypeMapping[parentName] = {};
}
// console.error("parent2", parentName, "DEF", def, "fieldName", fieldName);
this.fieldTypeMapping[parentName][fieldName] = value;
this.DEFMapping[def] = parentName;
// console.error("SET", parentName, this.fieldTypeMapping[parentName]);
// console.error("SET DEF", def, this.DEFMapping[def]);
}
}
} else if (element.nodeName === "fieldValue" && at === 'type') {
if (typeof parentName === 'undefined') {
// find name by looking up USE
var use = this.descendAttribute(element.parentNode, "USE");
parentName = this.DEFMapping[use];
// console.error("GET USE", use, this.DEFMapping[use]);
}
if (typeof parentName !== 'undefined') {
// console.error("GET", parentName, this.fieldTypeMapping[parentName]);
value = this.fieldTypeMapping[parentName][fieldName];
}
// console.error("parent3", parentName, "USE", use, "fieldName", fieldName,
"value", value);
}
}
if (typeof parent !== 'undefined' && typeof mapToMethod !== 'undefined' &&
(value === "" || value === "children")) {
if (typeof mapToMethod[parent.nodeName] !== 'undefined' && typeof
mapToMethod[parent.nodeName][element.nodeName] !== 'undefined') {
var tmpvalue =
mapToMethod[parent.nodeName][element.nodeName].substring(3,4).toLowerCase()+mapToMethod[parent.nodeName][element.nodeName].substring(4);
// lowercase first letter
if (tmpvalue !== 'proxy') { // must be set with containerField attribute
value = tmpvalue;
}
}
}
}
return value;
},

On Fri, May 8, 2020 at 3:54 AM John Carlson <yottzumm at gmail.com> wrote:

> Okay, I have put in some tracing code into DOM2JSONSerializer.  It appears
> that it is traversing up the tree as much as possible, even after it goes
> down.  So I get to about 23 levels down, and can't proceed much farther.
> Seems like I'm playing a game of rogue?
>
> Anyway, If you want to debug my code, it's at:
> https://github.com/coderextreme/X3DJSONLD/blob/master/src/main/node/DOM2JSONSerializer.js
>
> I suggest searching for `parentNode`.  I'm going to try to get some sleep.
>
> I feel like a newb writing such code.  Thanks to people like Joe who make
> good test examples, we'll track this down.
>
> None of this affects code in either X_ITE or X3DOM!  My code in the
> JSONParser does JSON -> XML, not XML to JSON.  DOM2JSONSerializer is not in
> X_ITE or X3DOM to my knowledge. It does affect the X3DJSONLD.
>
> However, I am somewhat concerned that X_ITE may be "freezing" like my code
> when processing XML.  It may be worth searching for parentNode in x_ite or
> x_ite_dom.
>
> Use Joe's Skin Kick when testing.
>
> John
>
>
>
>
> On Fri, May 8, 2020 at 3:06 AM John Carlson <yottzumm at gmail.com> wrote:
>
>> New node.exe, no luck!
>>
>> Trying browserify (the --node sets it up for nodejs instead of web
>> browser).
>>
>> $ browserify --node xml2all.js -o foo.js
>>
>> Still waiting
>>
>> $ node foo.js ../data/JoeSkinTexcoordDisplacerKick.x3d
>>
>> hmmm.  Guess I'll try WASM next, if possible!
>>
>> John
>>
>>
>> On Fri, May 8, 2020 at 2:35 AM John Carlson <yottzumm at gmail.com> wrote:
>>
>>> Hmm.  Well, node with 32GB of memory doesn't seem to finish either.
>>> Looking into a new node.exe for my system.
>>>
>>> On Fri, May 8, 2020 at 2:00 AM John Carlson <yottzumm at gmail.com> wrote:
>>>
>>>> X3dToJson.xslt wins (finishes).
>>>>
>>>> This is why we don't want to implement the XML/DOM Prototype Expander
>>>> in JavaScript (not that this message has anything to do with Prototype
>>>> Expanding, more likely my newbie JavaScript experience). I think that
>>>> ProtoExpanding on the server can work extremely well.
>>>>
>>>> The players:
>>>>
>>>> X3dToJson.xslt (winner)
>>>> $ sh don.sh ../data/JoeSkinTexcoordDisplacerKick.x3d
>>>>
>>>> DOM2JSONSerializer.js (loser)
>>>> $ node xml2all.js ../data/JoeSkinTexcoordDisplacerKick.x3d
>>>>
>>>> 1 Point for XSLT!
>>>>
>>>> John
>>>>
>>>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://web3d.org/pipermail/x3d-public_web3d.org/attachments/20200508/b9eef25a/attachment.html>


More information about the x3d-public mailing list