I am trying to get the child XML tag names in my AS3 program. For example, I have a file with information like this:
<LocationInfo>
<City>New York City</City>
<State>NY</State>
<Zip>10098</Zip>
</LocationInfo>
I load the file into an ArrayCollection and can access each item I need by name such as
[“City”] // Returns New York
Instead of getting the value, what I am trying to do is get the tag name such as State or Zip instead of NY or 10098.
When dealing with XML, you’re almost always better off using an XMLListCollection. For the most part, you wont’s ACTUALLY need the additional functionality of an ArrayCollection and the XMLListCollection will certainly make things a lot easier. Further, ArrayCollections don’t always serialize things correctly. I can’t give you a specific circumstance, but I do know that I have had to refactor because the XML wasn’t properly stored. Finally,
XMLListCollection.toXMLString()will give you a far better view of the data’s state thanArrayCollection.toStringever could.With an XMLListCollection, what you’re looking for would be done in one of the following:
If you really MUST use ArrayCollection, then you can use the for… in syntax to achieve what you want: