# Finding a node in XML file via node attrib?

**URL:** https://forum.kirupa.com/t/finding-a-node-in-xml-file-via-node-attrib/149156
**Category:** Uncategorized
**Created:** [May 26, 2005, 1:55pm UTC](https://forum.kirupa.com/t/finding-a-node-in-xml-file-via-node-attrib/149156 "2005-05-26T13:55:09Z")
**Posts on this page:** 1
**Page:** 1

<div class="post-metadata">

### Author: ![mindfriction](https://yyz1.discourse-cdn.com/flex011/user_avatar/forum.kirupa.com/mindfriction/32/172_2.png) [@mindfriction](https://forum.kirupa.com/u/mindfriction)
#### Post date: [May 26, 2005, 1:55pm UTC](https://forum.kirupa.com/t/finding-a-node-in-xml-file-via-node-attrib/149156/1 "2005-05-26T13:55:09Z")

</div>

Hi guys,

I thought this was going to be easy! I would like to search an XML file for a particular data set i.e. set of nodes depending on a passed variable. However, storing a subset of my XML file via

```auto
var gallery = this.firstChild;

```

and then searching ‘gallery’ as you would an array-using a for()-doesn’t work since this.firstChild isn’t returning an array :(. Any ideas?  
A sample of my XML and function are below.

Cheers! :thumb:

```auto

<gallery>
    <collection title="Christmas 2004">
        <picture title="Tiny Disk" thumb="portfolio_images/thumbs/tinydisk.jpg" description="portfolio_text/tinydisk.txt" image="portfolio_images/tinydisk.jpg"/>
        <picture title="Plug" thumb="portfolio_images/thumbs/plug.jpg" description="portfolio_text/plug.txt" image="portfolio_images/plug.jpg"/>
	</collection>
	<collection title="Christmas 2004">
        <picture title="Tiny Disk" thumb="portfolio_images/thumbs/tinydisk.jpg" description="portfolio_text/tinydisk.txt" image="portfolio_images/tinydisk.jpg"/>
        <picture title="Plug" thumb="portfolio_images/thumbs/plug.jpg" description="portfolio_text/plug.txt" image="portfolio_images/plug.jpg"/>
	</collection>
</gallery>

```

And the AS function…

```auto

function getCollection(collection) {
	//set the popup invisble when choosing a new gallery
	var gallery_xml = new XML();
	gallery_xml.ignoreWhite = true;
	gallery_xml.onLoad = function(success) {
		if (success) {
			trace("XML loaded");
			var gallery = this.firstChild
			trace("gallery:" +gallery instanceof Array);
			for(var i=0; i< gallery.length; i++){
				trace("searching for collection...");
				//find collection data
				if(gallery*.attributes.title==collection) {
					trace(collection+ " collection found");
					//store collection parent node
					var collection = gallery*.childNodes;
					collectionInfo.text = collection.attributes.title;
					var totalItems = collection.childNodes.length;
					buildGallery(collection, totalItems);
					break;
				} else if(i==gallery.length) {
					trace("Collection not found!");
					galleryInfo.text = "Not found";
					break;
				}
			}
			
		} else {
			trace("Error loading XML file");
		}
	};
	gallery_xml.load("gallery.xml");
}

```
