1

I try to read a specific value of a XML feed. Evertyhing is working but I want to read the "StartTime=" value too.

This is the XML:

<Program StartTime="17:00:00" EndTime="17:30:00">
<Name>name</Name>
</Program>

And this is the code:

$.ajax({
        type: "GET",
        url: "./data.xml",
        dataType: "xml",

        error: function (e) {
            alert("An error occurred while processing XML file");
            console.log("XML reading Failed: ", e);
        },

        success: function (response) {


            $("ul").children().remove();

            $(response).find("Program").each(function () {
                var _name = 'Program: ' + $(this).find('Name').text();
                console.log(_name);
                var _time = 'Time: ' + $(this).find('StartDateTime').text();

                // add content to the HTML
                $("ul").append('<li>' + _name + '</li>');
                $("ul").append('<li>' + _time + '</li>');

            });
        }
    });
}

I found some interesting information, but I can't actually use it...

1 Answer 1

1

The StartTime is an attribute of <Program>, not an element/node inside it. find() is for elements that are descendants.

Use attr() instead

Try:

var _time = 'Time: ' + $(this).attr('StartDate')
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.