Jump to content

battling to see how to load following xml into array for dynamically populating a listbox select


Greywacke

Recommended Posts

hi there :) i have the following xml which needs parsing...

<?xml version="1.0" encoding="utf-8"?><root>	<lvdk akid="267" ak="Requirement" kw="0.075">		<lvdv avid="267" av="Purchasing a new phone system to save costs" vw="8.000"/>	</lvdk>	<lvdk akid="279" ak="Extentions" kw="0.250">		<lvdv avid="279" av="Less than 5" vw="0.200"/>		<lvdv avid="280" av="5 to 10" vw="0.500"/>		<lvdv avid="281" av="11 to 20" vw="1.000"/>	</lvdk></root>

then sofar i have the following piece of script which does the parsing once the xml is received:

			// load attribute keys & weighting / 1, containing attribute values & weighting / 10			var lvdk = xmldoc.getElementsByTagName("lvdk");			for (var k = 0; k < lvdk.length; k++) {				var i = 0;				var arr = new Array();				for (var v = 0; v < lvdk[k].attributes.length; v++) {					arr[v] = lvdk[k].attributes[v].value;				}				for (var v = lvdk[k].attributes.length; v < lvdk[k].childNodes.length; v++) {					var lvd = lvdk[k].childNodes[v];					arr[k][v] = new Array();					if (lvd.nodeName == "lvdv" && lvd.attributes) {						for (var i = 0; i < lvd.attributes.length; i++) {							arr[k][v][i] = lvd.attributes[i].value;						}					}				}				salert(arr);				//getlvds(arr);			}

salert displays the array on my page, yet the array does not contain the rest of the <lvdv> tags and their properties from the xml, in a multidimentional array... it just populates with the attributes of <lvdk>

can anybody see what is wrong with this block of code, and why it does not parse the rest of the xml document above?

 

the array returned should look like follows:

     '0' => "267"     '1' => "Requirement"     '2' => "0.075"     '3' ..            '0' => "267"            '1' => "Purchasing a new phone system to save costs"            '2' => "8.000"

and

     '0' => "279"     '2' => "Extentions"     '3' => "0.250"     '3' ..            '0' => "279"            '1' => "Less than 5"            '2' => "0.200"     '4' ..            '0' => "280"            '1' => "5 to 10"            '2' => "0.500"     '5' ..            '0' => "281"            '1' => "11 to 20"            '2' => "1.000"

as there are two instances of the lvdk tag...

 

somebody please help????

Link to comment
Share on other sites

ok nevermind got it! :Pleased: started listening to some visualization manifestation music and it came to me :Shock:

			// load attribute keys & weighting / 1, containing attribute values & weighting / 10			var lvdk = xmldoc.getElementsByTagName("lvdk");			for (var k = 0; k < lvdk.length; k++) {				var i = 0;				var arr = new Array();				for (var v = 0; v < lvdk[k].attributes.length; v++) {					arr[v] = lvdk[k].attributes[v].value;				}				var t = lvdk[k].attributes.length;				for (var v = 0; v < lvdk[k].childNodes.length; v++) {					var lvd = lvdk[k].childNodes[v];					if (lvd.nodeName == "lvdv" && lvd.attributes) {						arr[v+t] = new Array();						for (var i = 0; i < lvd.attributes.length; i++) {							arr[v+t][i] = lvd.attributes[i].value;						}					}				}				salert(arr);				//getlvds(arr);			}

hope this helps somebody else with a similar problem ;)

Edited by Pierre 'Greywacke' du Toit
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...