Thanks for the input Scott! I simply trying to find the easiest way
to dump a 2D xml structure into an array/object that can be easily
iterated through in a loop.
Do you think there is a better way than what i am trying to do? I'm
an experienced php/sql developer but still learning the ropes in AS 2.0
Your thoughts are much appreciated. Happy New Year.
- Mike D
.............................................
Mike Dunlop
// Droplab
[ e ] [EMAIL PROTECTED]
On Dec 28, 2006, at 1:49 PM, slangeberg wrote:
item.mediums = new Array();
Should be fine, however:
item.mediums[item.mediums.length]['id'] = m[i_m].attributes.id;
Looks like you're trying to access a 2D array or Object in array,
so you
would have to do something like:
var medium:Object = new Object();
medium.id = m[i_m].attributes.id;
medium.name = m[i_m].firstChild.firstChild.nodeValue;
.
.
item.mediums.push( medium );
This doesn't mean that what you're doing is necessarily a best
practice, but
I'm not sure what your motivation is to do so. If you simply want
to access
xml as a more manageable data object, you can use things like XPath or
Xml2Object(?).
-Scott
On 12/28/06, Mike Dunlop <[EMAIL PROTECTED]> wrote:
Hi gang,
I'm having difficulty parsing an xml file into a multidimensional
array and was wondering if anyone could see why the following isn't
working... My guess is that an object variable can't be an array?
XML Sample
---------------------------------------------------------------------
-
<list>
<cat id="4">
<name>Art Glass</name>
<notes></notes>
<mediums>
<medium id="18">
<name>Drypoint</name>
<notes></notes>
<img>media/18_medium_tn.jpg</img>
</medium>
</mediums>
</cat>
</list>
---------------------------------------------------------------------
-
Actionscript
---------------------------------------------------------------------
-
var arr:Array = xml.firstChild.childNodes;
for(var i:Number = 0; i < arr.length; i++) {
var item:Object = new Object();
item.id = arr[i].attributes.id;
item.name = arr[i].firstChild.firstChild.nodeValue;
item.notes =
arr[i].firstChild.nextSibling.firstChild.nodeValue;
/***** this part isn't working *******/
item.mediums = new Array();
if(arr
[i].firstChild.nextSibling.nextSibling.hasChildNodes())
{
var m:Array =
arr[i].firstChild.nextSibling.nextSibling.childNodes;
for(var i_m:Number = 0; i_m < m.length; i_m
++) {
item.mediums[item.mediums.length]
['id'] =
m[i_m].attributes.id;
item.mediums[item.mediums.length]
['name']
= m
[i_m].firstChild.firstChild.nodeValue;
item.mediums[item.mediums.length]
['notes']
= m
[i_m].firstChild.nextSibling.firstChild.nodeValue;
item.mediums[item.mediums.length]
['img'] =
m
[i_m].firstChild.nextSibling.nextSibling.firstChild.nodeValue;
}
}
/***** /this part isn't working *******/
}
---------------------------------------------------------------------
-
Thanks for your help guys!
Best,
Mike D
_______________________________________________
Flashcoders@chattyfig.figleaf.com
To change your subscription options or search the archive:
http://chattyfig.figleaf.com/mailman/listinfo/flashcoders
Brought to you by Fig Leaf Software
Premier Authorized Adobe Consulting and Training
http://www.figleaf.com
http://training.figleaf.com
--
: : ) Scott
_______________________________________________
Flashcoders@chattyfig.figleaf.com
To change your subscription options or search the archive:
http://chattyfig.figleaf.com/mailman/listinfo/flashcoders
Brought to you by Fig Leaf Software
Premier Authorized Adobe Consulting and Training
http://www.figleaf.com
http://training.figleaf.com
_______________________________________________
Flashcoders@chattyfig.figleaf.com
To change your subscription options or search the archive:
http://chattyfig.figleaf.com/mailman/listinfo/flashcoders
Brought to you by Fig Leaf Software
Premier Authorized Adobe Consulting and Training
http://www.figleaf.com
http://training.figleaf.com