title: How to sort XML based on date values using jQuery
body: <p>I have an XML structure and a date value. I need to sort and get the latest node from below xml. I am looking for descending sorting below xml based on StartDate value.</p>
  
  <p><div class="snippet" data-lang="js" data-hide="false">
  <div class="snippet-code">
  <pre class="snippet-code-html lang-html prettyprint-override"><code>&lt;PriceList&gt;
        &lt;PriceInfo&gt;
          &lt;Timestamp&gt;2015-02-19T06:33:10.255&lt;/Timestamp&gt;
          &lt;Value xsi:nil=\"true\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" &gt;3&lt;/Value&gt;
          &lt;Unit&gt;eur/kwh&lt;/Unit&gt;
          &lt;StartDate&gt;2015-02-16T00:00:00&lt;/StartDate&gt;
          &lt;EndDate&gt;2015-02-16T00:00:00&lt;/EndDate&gt;
          &lt;BaseAmount xsi:nil=\"true\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" /&gt;
          &lt;BaseAmountUnit /&gt;
        &lt;/PriceInfo&gt;
        &lt;PriceInfo&gt;
          &lt;Timestamp&gt;2015-02-11T06:43:10.255&lt;/Timestamp&gt;
          &lt;Value xsi:nil=\"true\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" /&gt;
          &lt;Unit&gt;eur/kwh&lt;/Unit&gt;
          &lt;StartDate&gt;2015-02-11T00:00:00&lt;/StartDate&gt;
          &lt;EndDate&gt;2015-02-16T00:00:00&lt;/EndDate&gt;
          &lt;BaseAmount xsi:nil=\"true\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" &gt;4&lt;/BaseAmount&gt;
          &lt;BaseAmountUnit /&gt;
        &lt;/PriceInfo&gt;
        &lt;PriceInfo&gt;
          &lt;Timestamp&gt;2015-02-10T06:33:10.255&lt;/Timestamp&gt;
          &lt;Value xsi:nil=\"true\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" &gt;5&lt;/Value&gt;
          &lt;Unit&gt;eur/kwh&lt;/Unit&gt;
          &lt;StartDate&gt;2015-02-10T00:00:00&lt;/StartDate&gt;
          &lt;EndDate&gt;2015-02-16T00:00:00&lt;/EndDate&gt;
          &lt;BaseAmount xsi:nil=\"true\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" /&gt;
          &lt;BaseAmountUnit /&gt;
        &lt;/PriceInfo&gt;
      &lt;/PriceList&gt;</code></pre>
  </div>
  </div>
  </p>
  
  <p>I have written it like this,</p>
  
  <p><div class="snippet" data-lang="js" data-hide="false">
  <div class="snippet-code">
  <pre class="snippet-code-js lang-js prettyprint-override"><code> var result = $(priceList).find("PriceInfo").sort(function (a, b) {
                      debugger;
                      var textA = $(a).find('StartDate').text();
                      var textB = $(b).find('StartDate').text();
  
                      if (textA &lt; textB)
                          return 1;
                      if (textA &gt; textB)
                          return -1;
                      return 0;
                  });</code></pre>
  </div>
  </div>
  </p>