Awesome Ron -- Thanks much!!
Best,
Mike D
.............................................
Mike Dunlop
// Droplab
[ e ] [EMAIL PROTECTED]
On Dec 28, 2006, at 2:04 PM, Ron Wheeler wrote:
Why would you not put this into an object and make your life simple?
The list object has a single property - an array of cats. (list
probably should be called cats but that is just a naming thing.)
Each cat object seems to have a name property and a note property
and an array of medium objects.
The medium seems to have 3 properties.
You can build a constructor for each of list, cat and medium that
takes an XML sub-tree as an argument and parses its incoming tree
to create itself. This way no one has to know anything about the
XML tree of its parents or children and parsing at each level gets
pretty simple.
Each class can use cloneNode to get the subtree to pass to the
child's constructor once it has found out what kind of node was in
the tree that was passed in to the class's level.
We do this a lot and it works really well as things change. You
only have to fix the constructor of the object and do not have to
go searching for the guy who is doing the parsing if, for example,
you add a date to the cat. Just fix the constructor for the cat and
add a getter for the date. All your modifications are in one class
except for where date is used but the object wanting the cat's date
info already has the cat object, most of the time, so just has to
write
dateout=mycatinstance.getdate();
to get the new field.
Turning XML into arrays is going to be harder to write and much
harder to maintain.
You might simplify the XML by removing single values from nodes to
attributes.
<list>
<cat id="4" name="Art Glass" notes="">
<mediums>
<medium id="18" name="Drypoint" notes="" img="media/
18_medium_tn.jpg" />
<medium id="19" name="Wetpoint" notes="" img="media/
19_medium_tn.jpg" />
</mediums>
</cat>
<cat id="5" name="Not so Arty Glass" notes="">
<mediums>
<medium id="11" name="Drypoint" notes="" img="media/
11_medium_tn.jpg" />
<medium id="12" name="Wetpoint" notes="" img="media/
12_medium_tn.jpg" />
</mediums>
</cat>
</list>
This makes it easier to parse since the only nodes are sub-trees
and attributes are easier to parse.
It also makes your XML smaller.
Ron
Mike Dunlop 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
_______________________________________________
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