title: How to sort XML data in an order?
body: <p>I have a set of the list items that I would like to automatically display from high to low on page load. Ideally using jquery or javascript. </p>
  
  <p>Here is my code.</p>
  
  <p>data.xml</p>
  
  <pre><code>&lt;cd&gt;
    &lt;presantage&gt;10%&lt;/presantage&gt;
  &lt;/cd&gt;
  &lt;cd&gt; 
    &lt;presantage&gt;50%&lt;/presantage&gt;
  &lt;/cd&gt;
  &lt;cd&gt;
    &lt;presantage&gt;5%&lt;/presantage&gt;
  &lt;/cd&gt;
  </code></pre>
  
  <p>For display xml data</p>
  
  <pre><code>$(document).ready(function(){
      $.ajax({
          type:"GET",
          url:"data.xml",
          dataType:"xml",
          success:xmlParser2
      });
     });
     function xmlParser2(xml){
      xml = $(xml).children();
      $(xml).children().each(function () {
  
         let tag = $(this).prop("tagName");
          let presantage = '&lt;div&gt;' + $(this).find("presantage").text() + '&lt;/div&gt;';
  
          let html = '&lt;li&gt;'+ (presantage)+'&lt;/li&gt;';
  
              $(".list").append(html);
      });
  }
  </code></pre>
  
  <p>For order elements</p>
  
  <pre><code>var ul = $(".list:first");
  var arr = $.makeArray(ul.children("li"));
  
  arr.sort(function(a, b) {
      var textA = +$(a).text();
      var textB = +$(b).text();
  
      if (textA &lt; textB) return -1;
      if (textA &gt; textB) return 1;
  
      return 0;
  });
  
  ul.empty();
  
  $.each(arr, function() {
      ul.append(this);
  });
  </code></pre>
  
  <p>html</p>
  
  <pre><code>&lt;ul class="list"&gt;&lt;/ul&gt;
  </code></pre>
  
  <p><a href="http://next.plnkr.co/edit/X7Er706IJYu2oak7?open=lib%2Fscript.js" rel="nofollow noreferrer">Plunker</a></p>