JSFiddle - React, Tailwind, and code Playground
by jyrkim
JavaScript
var xml = "<PriceList><PriceInfo><Timestamp>2015-02-19T06:33:10.255</Timestamp><Value xsi:nil=\"true\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" >3</Value><Unit>eur/kwh</Unit><StartDate>2015-02-16T00:00:00</StartDate><EndDate>2015-02-16T00:00:00</EndDate><BaseAmount xsi:nil=\"true\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" /><BaseAmountUnit /></PriceInfo><PriceInfo><Timestamp>2015-02-11T06:43:10.255</Timestamp><Value xsi:nil=\"true\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" /><Unit>eur/kwh</Unit><StartDate>2015-02-11T00:00:00</StartDate><EndDate>2015-02-16T00:00:00</EndDate><BaseAmount xsi:nil=\"true\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" >4</BaseAmount><BaseAmountUnit /></PriceInfo><PriceInfo><Timestamp>2015-02-10T06:33:10.255</Timestamp><Value xsi:nil=\"true\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" >5</Value><Unit>eur/kwh</Unit><StartDate>2015-02-10T00:00:00</StartDate><EndDate>2015-02-16T00:00:00</EndDate><BaseAmount xsi:nil=\"true\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" /><BaseAmountUnit /></PriceInfo></PriceList>",
xmlDoc = $.parseXML(xml),
$xml = $(xmlDoc),
$title = $xml.find("PriceInfo");
var result = $xml.find("PriceInfo").sort(function (a, b) {
//debugger;
var textA = $(a).find('StartDate').text();
var dateA = new Date(textA);
var textB = $(b).find('StartDate').text();
var dateB = new Date(textB);
if (dateA < dateB) return +1;
if (dateA > dateB) return -1;
return 0;
});
$.each(result, function (index, value) {
console.log(value);
})