开发者

Search Flex XML object to find attribute when given element name?

I have a Flex XML object as follows:

private var _xmlCountries:XML =

开发者_StackOverflow<Countries>
  <option value="AF">Afghanistan</option>
  <option value="AL">Albania</option>
  <option value="DZ">Algeria</option>
  <option value="AO">Angola</option>
  <option value="AI">Anguilla</option>
  ........
<Countries>;

This object is ok, and shows up correctly in debug mode. The problem is I have a country name i.e. private var _country:String = "Angola";, and I want to get the corresponding value 'AO' from the XML object. Do you know how to do this?

I have tried loads of Livedocs examples, but cant get it to work!!!

P.S. I am working on a HtpService & WebService driven app to display global weather conditions overlayed on a Google Maps interface. Going to make it available to the Flex community when finished.


Figured it out:

Converted the XML to an XMLListCollection:

var xmlList:XMLList = _xmlCountries.option;                               
_xmlCountriesListCollection = new XMLListCollection(xmlList);

Looped through the collection, searching for _country = "Angola":

for(var i:int = 0; i < _xmlCountriesListCollection.length; i++)
{
   if(_xmlCountriesListCollection[i] == _country)
   {
      codeISO = _xmlCountriesListCollection[i].@value;
      trace(codeISO);
   }
}

Output: AO

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜