tags:

views:

201

answers:

1

I am parsing xml file in javascript and after that want to cancatenate all the the data into string. but failing to do the same and it is returning undefined.

      GDownloadUrl("./include/dataemp2.xml", function(data) {
      var xml = GXml.parse(data);
      markers = xml.documentElement.getElementsByTagName("marker");
       for(var t=0;t<18;t++)
         {
           var temp= markers[index].getAttribute("address");
          html = html + temp;
          }
         });

it is returning as undefined because temp is not concatenating in "html"; whereas when i do this like html = html +markers[index].getAttribute("address"); it is giving me expected output;

A: 

your var temp is being re-declared inside your for loop, the index wasn't declared (I presume you meant t.

  GDownloadUrl("./include/dataemp2.xml", function(data) {
    var xml = GXml.parse(data);
    markers = xml.documentElement.getElementsByTagName("marker");
    var temp, html;
    for(var t=0;t<18;t++){
      temp = markers[t].getAttribute("address");
      html += temp;
    }
    alert(html);        
  });
scunliffe