View Full Version : push for XMLList
rrh
April 15th, 2008, 01:43 PM
I've got a fairly complicated criteria to select elements from some XML. So I thought I'd just make one XMLList, and then for each node in that list, push the node into a second XMLList if it meets the criteria I'm looking for.
But I can't find an equivalent for .push() for an XMLList. In fact, XMLList appears to be missing a lot of list manipulation methods that you'd think would be useful for a list: shift() pop() sort() splice() join()
What's up with that? Is there something about XMLList that would make it defy list-based manipulation?
wvxvw
April 15th, 2008, 04:28 PM
Hm... it's just different from array, but, generally speaking, you may combine those two =) Can you give an example of what you ware going to do, may be it's not that complicated? =)
Felixz
April 15th, 2008, 04:41 PM
var XMLList1:XMLList=someXML.data.(@attribute="asdasd");
var XMLList2:XMLList=someXML.data.(@attribute="56445";
var XMLList3:XMLList=someOtherXML.data;
var allXMLList:XMLList=XMLList1 + XMLList2 + XMLList3;
He meant this (generally how to create one XMLList from several).
On arrays u can
var arr1:Array=["dfsdf","ghgh"];
var arr2:Array=["3423","434"];
var allArr:Array=[];
allArr.concat(arr1,arr2);
rrh
April 15th, 2008, 05:20 PM
What I ended up doing for now was use an XML instead of XMLList, and .appendChild() instead of .push() But it's good to see XMLList has some of this functionality. I didn't think to just try adding it up.
wvxvw
April 15th, 2008, 06:19 PM
Why?.. I mean it'd be much more convinient to use Array.map() or Array.filter().
var xml0:XML = <xml>
<someNode attr='a' />
<someNode attr='c' />
</xml>;
var xml1:XML = <xml>
<someNode attr='b' />
</xml>;
var arr:Array = [];
var xmll:XMLList;
for each(var xl:XML in (xml0+xml1)..*){
arr.push(xl);
}
arr.map(mapFunc, null);
function mapFunc(o:XML, ix:int, a:Array):void {
trace(o.toXMLString());
o.@id = ix;
}
for each(var xn:XML in arr){
try{
xmll+=xn;
} catch (e:Error){
xmll = XMLList(xn);
}
}
trace('==================');
trace(xmll.toXMLString())
Powered by vBulletin® Version 4.1.10 Copyright © 2012 vBulletin Solutions, Inc. All rights reserved.