ADOBE AFTER EFFECTS: Forum Expressions Tutorials Creative Cloud

"new XML()" not working sometimes on Extendscript

COW Forums : Adobe After Effects Expressions

<< PREVIOUS   •   FAQ   •   VIEW ALL   •   PRINT   •   NEXT >>
Miguel de Mendoza
"new XML()" not working sometimes on Extendscript
on Jun 22, 2018 at 11:53:41 am
Last Edited By Miguel de Mendoza on Jun 22, 2018 at 1:59:09 pm

Hi,I'm creating XML objects with this sintax:
var element = "element";
var xml = new XML("<"+element+"/>");


But sometimes it doesn't work. On the navigation tab, in the toolkit, "xml" appears as an empty xml object.

For example, in this code:

function KT_Data(name, value){
this.name = (!name)?this.constructor.name : name;
this.value = (!value)?0: value;

this.toXml = function(xml) {
var newXml = new XML("<" + this.name+ "/>"); //WORKS
newXml.@type = "KT_Data";
newXml.@class = this.constructor.name;
for (var property in this) {
var prop = this[property];
if (typeof prop == "function") {continue}
if (prop instanceof KT_Data){
prop.toXml(newXml);
} else if (prop instanceof Array) {
this.arrayToXml(newXml, prop, property);
} else {
newXml[property] = prop;
}
}
xml.appendChild(newXml);
return xml
}

this.arrayToXml = function(xml, property, nodeName) {
var newXml = new XML("<" + nodeName+ "/>"); //NOT WORKING
newXml.@type = "Array";
for (var i = 0; i < property.length; i++) {
var element = property[i];
var childXml = new XML("<el />");
if (typeof element == "function") {continue}
if (element instanceof KT_Data){
element.toXml(childXml);
newXml.appendChild(childXml);
} else if (element instanceof Array) {
this.arrayToXml(childXml);
newXml.appendChild(childXml);
} else {
newXml = element;
}
}
xml.appendChild(newXml);
return xml
}
}


KT_Obj.prototype = new KT_Data();
KT_Obj.prototype.constructor = KT_Obj;


function KT_Obj(name, xml) {
this.name = (!name)?this.constructor.name : name;
this.arr = ["Array"];
this.bool = true;
}

var obj= new KT_Obj();
var xml = new XML("<Root/>"); //WORKS
var tabXml = obj.toXml(xml);



It works when I create the root element and inside toXml() function, but not working inside arrayToXml().

Someone can figure out why is this happening?


Return to posts index

<< PREVIOUS   •   VIEW ALL   •   PRINT   •   NEXT >>
© 2018 CreativeCOW.net All Rights Reserved
[TOP]