Dynamic access your xml data

Categories Actionscript

Let’s say you have this xml data in an external file data.xml:

ActionScript

  1. <app>
  2.   <usa>
  3.    <Alabama pic="somepic.jpg" info="some info" />
  4.    <Alaska pic="somepic.jpg" info="some info" />
  5.    <Arizona pic="somepic.jpg" info="some info" />
  6.   </usa>
  7.  </app>

If you want to access your Alaska info data in actionscript, using just the name Alaska in a variable you can do:

ActionScript

  1. // assuming you loaded your external xml in xmlData
  2.  
  3. var country:String = "Alaska"
  4.  
  5. xmlData.usa.children().(name() == country).@info
Share this
Facebooktwitter

No Comments

Leave a Reply

Your email address will not be published. Required fields are marked *