Filtering XML for specific tags

I have learned all I needed to know about flash and XML so far from this outstandingly clear and well-written article here on kirupa: http://www.kirupa.com/developer/flashcs3/using_xml_as3_pg1.htm. Seriously, this is the best tutorial on the topic I have ever come across.

There is, however, one case that occurred to me recently, which isn’t covered. Maybe it’s too specific, or maybe there is no solution to it…

How can I filter an XML for specific tag-types?

I want to do the following: I have written a base-class for preloading XML and images. I want to make it useable for many future-projects. However, the XML-Structure of my projects vary a lot.

What I need is a way to retrieve all tags of a given type, wherever they are. For example, I want to get all images tagged with <picture></picture>-tags from the xml, independently of the structure:


<gallery>
<picture>image1.jpg</picture>
<picture>image2.jpg</picture>
</gallery>


<buttons>
 <button><name>Great A</name><picture>image1.jpg</picture></button>
 <button><name>Great B</name><picture>image2.jpg</picture></button>
 </buttons>

I need a way to get a list off all pictures (i.e. image1.jpg, image2.jpg), which works for both cases (and all others). The one thing consistent is supposed to be the tag-type (i.e “picture” in this case).

Is there a way to do so?