javascript array

http://www.w3schools.com/xml/xml_to_html.asp

From above example, I would like to return to array in javascript. How can I do that?
The ideal result will be like

Array("data1","data2")......

Thanks
LVL 1
ITsolutionWizardAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Ray PaseurCommented:
That's a very, very old example and you should not be using it.  We use jQuery for this sort of thing now-a-days and we use JSON instead of XML.

How does this fit into the PHP Zone?
0
ITsolutionWizardAuthor Commented:
Regardless, I want to use my existing codes base. Please continue if you know how.
0
Slick812Commented:
greetings ITsolutionWizard, , In the code for the w3shools web page you gave they have this -
    xmlDoc=xmlhttp.responseXML;

as what I consider to be the "Return" from an XML ajax request made with this -
     xmlhttp.open("GET","cd_catalog.xml",false);

so I can not understand what you mean, OR what you might need when you say - "return to array in javascript."
you say the result would be like -
     Array("data1","data2")

but as you may know, , any AJAX return is just a "text" output from the server, if you use the -
   xmlhttp.responseXML
then the javascript will use the text as a XML DOM object with properties, So if you use the XML as the w3schools does, then you will have to use the XML tags to assign values, but you do not get an array.

If you abandon the XML ajax formatting, then you can get a CSV delimited text, and use -
    ajax.responseText.split("\n");
to get an array.
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
ITsolutionWizardAuthor Commented:
Then just send me example from xml string to array written in JavaScript
0
Slick812Commented:
you say you want an array fron XML? ?, below is untested code , that I just wrote, for here, this -
for (i=0;i<x.length;i++)
  {
  array1.push( x[j].getElementsByTagName("ARTIST")[0].childNodes[0].nodeValue );
  }

should place the artist values from the XML into array1
<script>
var xmlhttp = false;
/*@cc_on
@if (@_jscript_version>=5)try{xmlhttp = new ActiveXObject('Msxml2.XMLHTTP.4.0');} catch(e){
	try{xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");} catch(e){
	try{xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");} catch(E){xmlhttp=false;}}}
	@else xmlhttp = false;
@end @*/
if(!xmlhttp && typeof XMLHttpRequest !='undefined'){try{xmlhttp = new XMLHttpRequest();} 
catch(e){xmlhttp = false;}}

array1 = [];

xmlhttp.open("GET","cd_catalog.xml",false);
xmlhttp.send();
xmlDoc=xmlhttp.responseXML;


var x=xmlDoc.getElementsByTagName("CD");
for (i=0;i<x.length;i++)
  {
  array1.push( x[i].getElementsByTagName("ARTIST")[0].childNodes[0].nodeValue );
  }

document.write(array1[0]);
</script>

Open in new window


hopefully you can see some of what this does, ask questions if you need more info.
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
JavaScript

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.