Jump to content

retrieving multidimentional array from xml and displaying as string


Recommended Posts

hi all,got this slight issue, tried various scripting layouts, but none of them work. when i started, at first just got only the subarray 4 (catattr node attributes 0 - 3)...here is the xml:

<?xml version="1.0" encoding="UTF-8" ?><root>	<pricecat>		<catid>1</catid>		<svcid>1</svcid>		<catdesc>Category A</catdesc>		<catprice>20</catprice>		<catattr id="1" desc="canopy_req" val="new_white"/>	</pricecat>	<sql></sql></root>

and here is the parser, followed by the dhtml that is supposed to create a new list option. with the passed array.

// get category informationvar pricecat = xmldoc.getElementsByTagName("pricecat");for (var r = 0; r < pricecat.length; r++) {	var i = 0;	var len = (parseInt(pricecat[r].childNodes.length - 1) / 2) + 1;	var arr = new Array(len);	for (var c = 0; c < pricecat[r].childNodes.length; c++) {		var pcn = pricecat[r].childNodes[c];		if (pcn.childNodes.length > 0) {			arr[i] = pcn.firstChild.data;			i++;		} else if (pcn.attributes > 0) {			arr[i] = new Array(2);			for (a = 0; a < pcn.attributes.length; a++) {				arr[i][a] = pcn.attributes[a].value;			}			i++;		}	}	//salert(arr);	addrecord(arr);}// skip irrelevant scripting// *******************// addrecord functionfunction addrecord(arr) {	for (i = 0; i < arr.length; i++) {		if (arr[i] instanceof Array) {			arr[i] = arr[i].join(";;;");		}	}	alert(arr.join(";;"));	var opt = document.createElement('option');	opt.text = arr[2] + "\u00a0\u00a0\u00a0\u00a0\u00a0(" +				// category description			   arr[3] + ")";						// category lead price	opt.value = arr.join(";;");							// save array as value	var sel = document.getElementById("list_categories");	try {		sel.add(opt, null);			// standards compliant; doesn't work in IE	}	catch(ex) {		sel.add(opt);				// IE only	}}

with this, it adds the record fine, but the value does not include the joined subarray from the catattr function :/could somebody please help! afraid i can't see the bees for their honey :)

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

lol found the prob ^^its pcn.attributes.length if i want to use it like that :)so i changed it to pcn.attributes ^^ussue RESOLVED :)

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...