Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

XML to Array

Status
Not open for further replies.

dragonballs2

Programmer
Feb 21, 2011
1
CA
I am having trouble finding a function that converts XML to a multidimensional array. I'll appreciate your input, please.
 
you could use the DomParser. to extract values from the xml. From there you could build up your array.
something like
Code:
var xml = getxml();
var doc = parser.parseFromString(xml, "text/xml");
var elements = doc.getElementsByTag('name of tag');

var array = new Array();
for(var i = 0; i < elements.length; i++)
{
   array.push(elements[i].innerHtml);
}
a library like jquery would make this even easier
Code:
var xml = getxml();
var array = new Array();
$(xml).each(function(i, e){
  array.push($(e).val());
});

Jason Meckley
Programmer

faq855-7190
faq732-7259
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top