0

How can i extract XML from the following link?: http://clarendoncollegeactivities.blogspot.com/feeds/posts/default

I should be able to do something like this:

 $.ajax({
    url: "http://clarendoncollegeactivities.blogspot.com/feeds/posts/default",

    dataType: "xml",

    success: function (xml) {
    var entry = $(xml).find('title').eq(0).text();

    alert(entry);

    }

 });

But it doesn't work, as the URL doesn't have the XML extension.

1
  • the title of question is misleading ... Commented Oct 18, 2011 at 20:52

2 Answers 2

1

You will have to first fetch the XML before parsing it. And to fetch it you will need to respect the same origin policy restriction which is built into browsers and which forbids you from sending cross domain AJAX requests. So you could start by writing a server side bridge using your favorite server side language that you will host on your domain and which will fetch the XML file. Then you will send an AJAX request you your script which is hosted on your domain:

$.ajax({
    url: "/myscript",
    dataType: "xml",
    success: function (xml) {
        var entry = $(xml).find('title').eq(0).text();
        alert(entry);
    }
});

then you can hope to get this success handler executed and start to do the actual work of parsing. I would recommend you going through the following guide if you intend to perform cross domain AJAX calls.

And because parsing XML with javascript might not be the best and most performant thing to do, and because you already have a server side script on your domain that performs the fetching of the XML you could adapt this script to do the parsing as well and simply send the results of this parsing to the client javascript AJAX call.

Sign up to request clarification or add additional context in comments.

Comments

0

I'd capture the return response as text and use jquery's parseXML() function.

http://api.jquery.com/jquery.parsexml/

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.