karthika pommudu

karthika pommudu

  • 1.6k
  • 254
  • 6k

how to get xml parse value in loop..

Mar 16 2019 6:31 AM
Here,I want to get (loop)the number of Latitude & Longitude from response to var data,data1.
 
Help me to solve this ...
 
{"Last30PointsDataJSon":[{"Latitude":11.766470,"Longitude":77.884158,"Speed":11.00,"PositionTime":"16/Mar/2019 04:32:32 PM","PositionType":"GPS","Direction":"NorthWest","ACC":"Off","Battery":"100%","GSMStrength":"Strong Signal","PowerStatus":"Power Connected"},{"Latitude":11.766087,"Longitude":77.884393,"Speed":35.00,"PositionTime":"16/Mar/2019 04:32:22 PM","PositionType":"GPS","Direction":"NorthWest","ACC":"Off","Battery":"100%","GSMStrength":"Strong Signal","PowerStatus":"Power Connected"},{"Latitude":11.765148,"Longitude":77.884998,"Speed":45.00,"PositionTime":"16/Mar/2019 04:32:12 PM","PositionType":"GPS","Direction":"NorthWest","ACC":"Off","Battery":"100%","GSMStrength":"Strong Signal","PowerStatus":"Power Connected"}]}
  1. var txt = '<?php echo $response;?>' //here,I got the Json response (above response)  
  2. var parser, xmlDoc;  
  3. parser = new DOMParser();  
  4. xmlDoc = parser.parseFromString(txt,"text/xml");  
  5. var data = xmlDoc.getElementsByTagName("Latitude")[0].childNodes[0].nodeValue;  
  6. var data1 = xmlDoc.getElementsByTagName("Longitude")[0].childNodes[0].nodeValue;  
  7. console.log(data,',',data1);  
  8. var locations=[  
  9. [data,data1]  
  10. ];  
..............................................................

Answers (2)