tags:

views:

181

answers:

1

Say for example, I have an XML file with 100 "person" nodes, and I want the first 30. Or possibly 51 - 100. Is there any way to do this with e4x syntax to return an XMLList?

+1  A: 
var list:XMLList = xml.person;
var start:int = 10;
var end:int = 40;
var filteredList:XMLList = new XMLList();
for(i = start - 1; i < end; i++)
  filteredList += new XML(XML(list[i]).toXMLString());
Amarghosh
var filteredList:XMLList; should bevar filteredList:XMLList = new XMLList();
Eric Belair
Oops, corrected. Thanks :)
Amarghosh
Error: TypeError: Error #1086: The appendChild method only works on lists containing one item. Replacing the single expression in the for loop helped: var tempNode:XML = list[i]; filteredList += tempNode;
eterps
Thanks for the correction - updated the code to fix it.
Amarghosh
If you're converting the `list[i]` XML to String, then back to XML, only to create a copy of the XML object, you could just use list[i].copy();. I'm not sure why you're creating a copy though. simply doing `filteredList += list[i];` should work, right?
Niko Nyman