I wanted to create a list of Strings from only the attributes of an XMLList, and I wanted them separated with carriage returns.

The "toXMLString()" method does this automatically on attributes.
Attributes are typed as XMLList.

  1.  
  2. var myXmlList:XMLList=XMLList(<B><P name="Orange"/><P name="Grape"/><P name="Pear"/></B>).P;
  3. trace(myXmlList..@name.toXMLString());
  4. //Outputs multiple values of all "name" attributes separated with carriage returns automatically.
  5. Orange
  6. Grape
  7. Pear
  8.  

Putting the values of an XMLList as an Array might be useful also.

Being separated by carriage returns makes it easy to convert to an Array by using the String "split" method.

Wrap this into a function for easy use.

  1.  
  2. function xmllistToArray(list:XMLList):Array
  3.              {
  4.                  return list.toXMLString().split("\n");
  5.              }
  6.  

3 Responses to “Converting an XMLList to an Array in AS3”
  1. Thanks a lot :-)

  2. Rui Monteiro says:

    Thanks !!!

  3. Thanks :) Handy function

Leave a Comment

Thanks for visiting www.keith-hair.net