Version 4 (modified by nick, 15 years ago) (diff)

add javascript example

Having identified which feed to use, it is then very easy to make use of this feed data in your applications.

Below, we hope to present example code for using OpenGuides RSS feeds in a number of common web application programming languages.


Ruby On Rails


Django (Python)


Note that the JavaScript? will either need to come from the same server as the feed, or be running with the browser granting it extra security rights, otherwise you'll get a security exception when you try to request something off another server.

An example for pulling out titles and modified dates from the recent changes RSS feed, and chucking them into a paragraph with the id "data" follows.

// This will fetch the Recent Changes RSS from an OpenGuide on the
//  same server as the script. 
// It will then output the node title and modified date, into a
//  paragraph on the page with id "data"
// You will need to ensure that there is:
//      <p id="data" />
// Already on the page before calling this
var feed_url = "/og-wiki/wiki.cgi?action=rc;format=rss";

function go() {
    // Get a XMLHttpRequest Object
    var xmlhttp = false;
    if (!xmlhttp && typeof XMLHttpRequest!='undefined') {
        xmlhttp = new XMLHttpRequest();
    } else {
        xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");

    // Use it
    if(xmlhttp) {"GET", feed_url, false);

        var status = xmlhttp.status;
        var p = document.getElementById("data");

        if(status == 200 || status == 304 || status == 0 || status == null) {
            // Bingo, we have the feed
            var feed = xmlhttp.responseXML;

            // Go find the individual item entries
            var items = feed.getElementsByTagName("item");

            // Loop over the items, getting the titles and dates out
            for(var i=0; i<items.length; i++) {
                var item = items[i];
                var ic = item.childNodes;

                var title;
                var date;
                for(var j=0; j<ic.length; j++) {
                    var tag = ic[j];
                    if(tag.nodeType == Node.ELEMENT_NODE) {
                        if(tag.tagName == "title") {
                            title = tag;
                        if(tag.tagName == "dc:date") {
                            date = tag;

                // Add a div with the title and date
                var sub_div = document.createElement("div");
                    title.firstChild.nodeValue + " - modified " + date.firstChild.nodeValue
        } else {
            var text = "Error code " + status;