# Counting xml file elements

**URL:** <https://forum.kirupa.com/t/counting-xml-file-elements/123960>\
**Category:** Uncategorized\
**Created:** [September 28, 2004, 9:47pm UTC](https://forum.kirupa.com/t/counting-xml-file-elements/123960 "2004-09-28T21:47:09Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![Pneumonic](https://avatars.discourse-cdn.com/v4/letter/p/aeb1de/32.png) [@Pneumonic](https://forum.kirupa.com/u/Pneumonic)\
**Post date:** [September 28, 2004, 9:47pm UTC](https://forum.kirupa.com/t/counting-xml-file-elements/123960/1 "2004-09-28T21:47:09Z")

</div>

I’m trying to generate a random background and css file using an xml document. My xml structure is as such:

```php

<?xml version="1.0" encoding="iso-8859-1"?>
<backgrounds> 
			  <pic>
			  	<image>http://www.21bluefish.com/images/21bluefish_logo5.jpg</image>
				<name>Logo 5</name>
				<location>My Computer</location>
			  </pic>
			   <pic>
					<image>http://www.21bluefish.com/images/Me_coat_small.jpg</image>
					<name>Me coat small</name>
					<location>Calumet City, IL</location>
			   </pic>
</backgrounds>

```

It’s pretty standard.

What I’ve got so far as far as code is this:

```auto

backgrounds = new Array("0.jpg", "1.jpg", "2.jpg", "3.jpg");
function randomBackground(){
	randomNumber = random (backgrounds.length);
	loadMovie (backgrounds[randomNumber], "_root.background");
}
randomBackground();
var format = new TextField.StyleSheet();
var path = "http://www.21bluefish.com/" + randomNumber + ".css";
format.load(path);
format.onLoad = function(loaded) {
	if (loaded) {
		output.styleSheet = format;
		myLoadVar = new LoadVars ();
		myLoadVar.load("john.txt")
		myLoadVar.onLoad = function (success){
			if (success == true) {
				output.variable = "john"
				output.htmlText=myLoadVar.kirupa;
				}
			}

	} else {
		output.text = "Error loading CSS file!";
	}
};

```

The problem is, I don’t want to use an array like I have it right now, because then updating it is a pain. What I want to do is retrieve the xml file, count the _pic_ element and take that number and put it into a variable to multiply it by _random_. I then want to display the background file in an empty mc, as well as retrieve the _name_ and _location_ elements and display them in a text box. D\*\*n this sounds complicated now. Well, I’m stumped so any help or a kick or push in the right position would be wonderful. Thanks.
