JSFiddle - React, Tailwind, and code Playground
HTML
<textarea id='src' style='box-sizing: border-box; width: 100%; height: 200px;'><Locations>
<Location>
<Id>790</Id>
<Name>DHA Office</Name>
<Latitude>31.4737</Latitude>
<Longitude>74.3771</Longitude>
<Distance>0.74</Distance>
<Address>Sector Y</Address>
<City>Lahore </City>
<Subcategory>Convenience Store</Subcategory>
<Appid>1</Appid>
<Stars>2</Stars>
<Options>2,,,,,,,,,,</Options>
</Location>
<Location>
<Id>729</Id>
<Name>McDonald's</Name>
<Latitude>31.4749</Latitude>
<Longitude>74.3772</Longitude>
<Distance>0.67</Distance>
<Address>486/ B</Address>
<City>Lahore </City>
<Subcategory>Convenience Store</Subcategory>
<Appid>1</Appid>
<Stars>5</Stars>
<Options>3,,,,,,,,,,</Options>
</Location>
<Location>
<Id>732</Id>
<Name>Lahore Zoo</Name>
<Latitude>31.5563</Latitude>
<Longitude>74.3261</Longitude>
<Distance>4.79</Distance>
<Address>92 Mall Road</Address>
<City>Lahore </City>
<Subcategory>Convenience Store</Subcategory>
<Appid>1</Appid>
<Stars>3</Stars>
<Options>6,7,,,,,,,,,</Options>
</Location>
</Locations></textarea>
<textarea id='dst' style='box-sizing: border-box; width: 100%; height: 200px;'></textarea>
JavaScript
var yourXmlString = $('#src').val();
var l = $(yourXmlString).find('Location');
l.sort(function(a, b) {
var v1 = parseInt($(a).children('Stars').first().text());
var v2 = parseInt($(b).children('Stars').first().text());
v1 = isNaN(v1) ? 0 : v1;
v2 = isNaN(v2) ? 0 : v2;
return (v2 - v1);
});
$.each(l, function(i, v){
var c = $('#dst').val();
var s = $(v).children('Stars').first().text();
var sn = $(v).children('Name').first().text();
#var sc = $(v).children('Subcategory').first().text();
$('#dst').val(c + s + ':' + sn +\n');
});