, 당신은 거의 항상 XMLListCollection에를 사용하는 것이 더 낫다. 대부분의 경우 ArrayCollection의 추가 기능이 실제로 필요합니다. XMLListCollection을 사용하면 훨씬 쉽게 작업 할 수 있습니다. 또한 ArrayCollection은 항상 일을 올바르게 직렬화하지 않습니다. 특정 상황을 제공 할 수는 없지만 XML이 제대로 저장되지 않아서 리팩터링을해야한다는 것을 알고 있습니다. 마지막으로 XMLListCollection.toXMLString()
은 ArrayCollection.toString
보다 훨씬 더 나은 데이터 상태를 제공합니다. XMLListCollection에와
, 당신이 다음 중 하나에서 수행 될 것이다 찾고있는 당신이 정말로있는 ArrayCollection을 사용해야하는 경우
var coll:XMLListCollection = <xml-here/>
// Iterate through all of the children nodes
for(var i:int = 0; i < coll.children().length(); i++)
{
var currentNode:XML = coll.children()[ i ];
// Notice the QName class? It is used with XML.
// It IS NOT a String, and if you forget to cast them, then
// currentNode.localName() will NEVER be "city", even though it may
// trace that way.
var name:QName = currentNode.name(); // url.to.namespace::city
var locName:QName = currentNode.localName() // City
}
// get all city nodes in the current parent element
var currCities:XMLList = currentParentNode.cities; // currentParentNode can be
// an XMLList, an XML object, an XMLListAdapter, or an XMLListCollection.
// This means that you can do something like coll.cities.cities, if there are
// children nodes like that.
for(i = 0; i < cities.length(); i++)
{
var currentCity:XML = cities[ i ];
}
// get all city nodes in all descendant nodes.
var cities:XMLList = currentParentNode.descendants(
new QName("url.to.namespace", "City")
);
for(i = 0; i < cities.length(); i++)
{
var currentCity:XML = cities[ i ];
}
는, 당신은 사용할 수있는 중 ... 구문 것은 달성하기 원하는 항목 :
// This is one of the few times I recommend anonymous typing. When dealing with
// XML (which likely has already been turned into a String anyway, but be safe)
// anonymous syntax can give you better results.
// it = iterant, I use this to contrast with i for my sanity.
for(var it:* in coll)
{
trace(it,"=",coll[ it ]);
}