'Sorting XML doesn't return a value

What I did was parse the the var a, sort and then display it. It doesn't return value or error.

var a = '<root><ap by="A" on="2021/10/01 14:03:24" lvl="4"></ap><ap by="A" on="2021/10/01 14:03:59" lvl="2"></ap><ap by="A" on="2021/10/01 14:04:01" lvl="5"></ap><ap by="A" on="2021/10/01 14:04:05" lvl="1"></ap></root>';


        $($.parseXML(a), function (log) {
        var ap = $(log).find($(this)).clone();

        ap.sort(function (a, b) {
            return (parseInt($(a).attr("lvl")) - parseInt($(b).attr("lvl")));
        });

        ap.find("ap").each(function () {
        var ap = $(this);
        var by = ap.attr("by");
        var on = kendo.parseDate(ap.attr("on"));
        var lvl = parseInt(ap.attr("lvl"));

                 
        if (apdate.html() != "") $("<br>").appendTo(apdate);
        $("<span" + props + ">").text(by + " (" + kendo.toString(on, User.datetimeFormat) + ") (" + lvl + ")").appendTo(apdate);

        });

I was able to display the data unsorted by using this. I assumed that the problem is in my sorting code.

        $($.parseXML(a).find("ap").each(function () {
        var ap = $(this);
        var by = ap.attr("by");
        var on = kendo.parseDate(ap.attr("on"));
        var lvl = parseInt(ap.attr("lvl"));
        var props = "";
          
        if (apdate.html() != "") $("<br>").appendTo(apdate);
        $("<span" + props + ">").text(by + " (" + kendo.toString(on, User.datetimeFormat) + ") (" + lvl + ")").appendTo(apdate);



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source