Traversing the XML tree

I have the following XML:

<MemberProvider  name="myName">
					<Name>Beacon Lighting</Name>
					<Address>219 21 William Street, Cannington WA 6107</Address>
					<Phone>08 9356 6422</Phone>
					<savingText>Members get 10 off RRP</savingText>
					<disclaimer>Also save 10 off grid connected solar power systems</disclaimer>
					<Name>Beacon Lighting</Name>
					<Address>61 Key Largo Dr, Clarkson WA 6030</Address>
					<Phone>08 9408 5445</Phone>
					<savingText>Members get 10 off RRP</savingText>
					<disclaimer>Also save 10 off grid connected solar power systems</disclaimer>
			</MemberProvider >
<MemberProvider name="myName">
<MemberProvider name="myName">

Now in my Javascript, I have

var xmlrows = xmlDoc.documentElement.getElementsByTagName("Marker");
		var xmlGroups = xmlDoc.documentElement.getElementsByTagName("MemberProvider");
		//for the number of Member Providers listed
		for (var i = 0; i < xmlrows.length; i++) {
			var xmlrow = xmlrows[i];
			var singleGroup = xmlGroups[i];
				var xmlcellLongitude = xmlrow.getElementsByTagName("Longitude")[0];
				var xmlcellLatitude = xmlrow.getElementsByTagName("Latitude")[0];
				var point = new GLatLng(parseFloat(, parseFloat(;
//get the name
				var name = singleGroup.getElementsByTagName("MemberProvider")[0].getAttribute("name");

Why do I have two variables loading the xml doc? The first appears to work, but the second (xmlGroups) does not. Every time I try and get the Name attribute from the MemberProvider node, it throws getElementsByTagName(“MemberProvider”)[0].getAttribute(“name”); is null or not an object.

Can anyone help before I have no hair left!!!

The way you have written your code looks strange to me because your looping through the <Marker> elements before you loop through the <MemberProvider> elements. See the below code for how i think it should be written out.

var providers = xmlDoc.documentElement.getElementsByTagName('MemberProvider');

// Loop through the "MemberProvider" elements
for (var i = 0; i < providers.length; i++) {
    var provider = providers[i],
        markers  = provider.getElementsByTagName('Marker'),
        name     = provider.getAttribute('name');
    if (markers.length) {
        for (var j = 0; j < markers.length; j++) {
            var marker    = markers[j],
                longitude = marker.getElementsByTagName('Longitude')[0],
                latitude  = marker.getElementsByTagName('Latitude')[0],
                point     = new GLatLng(parseFloat(, parseFloat(;

Thanks SgtLegend, massive help! greatly appreciated.

No problem