Hi I have looked around to find something simple that Iām looking for.
ex:
I have the php page that generates this file
imagine all those are small case
<PRODUCE>
<FRUIT>
<APPLE>
<KIND>Delicious</KIND>
<COLOR>Red</COLOR>
<PRICE>
<AMOUNT>.79</AMOUNT>
<PER>pound</PER>
</PRICE>
</APPLE>
</FRUIT>
</PRODUCE>
now i would like to be able to define those fields in flash as:
_root.applecolor = myXML.produce.fruit.apple.collor;
_root.appleprice = myXML.produce.fruit.apple.price.amount;
instead of accessing it: (example - not real path)
myXML.firstChild.childNodes[5].childNodes[3].description.firstChild.nodeValue;
I have found something close but still no cigar.
XML.prototype.traverseNodes = function(node) {
var i = 0;
var children = node.childNodes;
//required for performance issues (interpreter recalling childNodes)
if (node.nodeFuncs == undefined) {
node.nodeFuncs = new Object();
}
// add array for addProperty functions
while (children*) {
// DUPLICATE TAGS: We need to handle childNodes that contain duplicate nodeName entries
// The following works only if all nodeNames are equal for the entire childNodes list
// this is NOT a final solution, modify as needed
var flag = true;
if (children.length>1 && children[0].nodeName == children[1].nodeName) {
// for now, we assume all children are equal
if (i == 0) {
// Only addProperty for the first node
node.nodeFuncs[0] = function () {
return node.childNodes;
};
} else {
flag = false;
}
} else {
node.nodeFuncs* = function () {
return this.childNodes[arguments.callee.index];
};
// saving 'index' allows the interpreter to find the node when calling the 'nodeFunc'
node.nodeFuncs*.index = i;
// save the node index with the associated function
}
if (flag == true) {
// addProperty for each node except duplicate nodes
if (children*.nodeName.length && node.addProperty(children*.nodeName, node.nodeFuncs*, null)) {
//trace ("Property:"+child.nodeName+" added");
}
}
if (children*.childNodes.length>0) {
this.traverseNodes(children*);
}
i++;
}
//trace("traverseNodes");
};
XML.prototype.extendXML = function() {
if (this.childnodes.length>0) {
this.traverseNodes(this);
//trace("extendXML");
}
};
XML.prototype.onData = function(src) {
if (src == undefined) {
this.onLoad(false);
} else {
this.parseXML(src);
this.extendXML();
// OR this.traverseNodes( this ); and eliminate extendXML
this.loaded = true;
this.onLoad(true);
}
};
function myOnLoad(success) {
if (success) {
trace("Load succeeded!");
} else {
trace("Load failed!");
}
}
var myXML = new XML();
myXML.onLoad = myOnLoad;
myXML.ignoreWhite = true;
//myXML.load("data.php?ID="+ID);
myXML.load("data.txt");
Thank you.