  | |  | SV: [Flashcoders] Recursive xml function | SV: [Flashcoders] Recursive xml function
2004-02-25 - By Wallgren Jonatan
Back I don 't know if this will help you, but this extension saves the
nodenames of an xmlnode as properties of the node so you can access
nodes like this:
xmlObject = new
XML( <root > <catalog > <item >1 </item > <item >2 </item > <item >3 </item > <catalog > </
root >);
xmlObject.toObject();
trace(xmlObject.root.catalog.item[0].nodeValue);
//1
The method has some drawbacks, for example if you have a node in your
xml the has the same name of an internal property of the XMLnode object,
the internal property will be overwritten. On the positive side you
don 't have to store the data twice.
XMLNode.prototype.toObject = function() {
var children = this.childNodes;
for (var i = 0; i <children.length; i++) {
if (this[children[i].nodeName] == undefined) {
this[children[i].nodeName] = children[i];
} else if (this[children[i].nodeName].length =undefined) {
this[children[i].nodeName] = new
Array(this[children[i].nodeName]);
}
if (this[children[i].nodeName] instanceof Array) {
this[children[i].nodeName].push(children[i]);
}
if (children[i].hasChildNodes()) {
children[i].toObject();
}
}
}
Jonatan
=-- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- --
Supported by Fig Leaf Software
=-- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- --
Be sure to check the archives and the wiki:
http://chattyfig.figleaf.com/
=-- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- --
http://chattyfig.figleaf.com/cgi-bin/ezmlm-cgi?1:mss:105195
=-- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- --
To unsubscribe send a blank e-mail to:
Normal Mode: flashcoders-unsubscribe@(protected)
Digest Mode: flashcoders-digest-unsubscrive@(protected)
|
|
 |