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
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:
<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…
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");
}