HTML5, CSS3 & JS Experiments

By Martin Ivanov

XML to JSON JavaScript Objectifier Class

Run this page on a web-server with PHP support and use your browser's developer tools (Firebug, Chrome Developer Tools, etc) to see how it works and how to include XmlToJson in your project. Visit this page to learn about the API methods of the class.

Register the Class

<script src="AcidJs.XmlToJson/Scripts/AcidJs.XmlToJson.js"></script>

Usage and Code Insight

(function() {
    window.xmltojson = new AcidJs.XmlToJson({
        //rootFolder: "Martin/" // optional, default is empty string
    });
    window.xmltojson.getRemoteData({
        name: "rss",
        url: "http://acidjs.wemakesites.net/pages/whats-new/whats-new.rss",
        success: function(data) {
            console.log(data);
        }
    });
    window.xmltojson.getRemoteData({
        name: "feedburner",
        url: "http://feeds.feedburner.com/acidmartin",
        success: function(data) {
            console.log(data);
        }
    });
    /*window.xmltojson.getRemoteData({
        name: "slayer",
        url: "http://ws.audioscrobbler.com/2.0/",
        params: [
            {
                method: "album.getinfo"
            },{
                api_key: "XXXXXX" // use yor Last.FM API key here
            },{
                artist: "Slayer"
            },{
                album: "Seasons in the Abyss"
            }
        ],
        success: function(data) {
            console.log("data object: ", data); // return the entire data object
            console.log("JSON object: ", data.json); // return the converted XML to JSON object only
            console.log("data object name: ", data.name); // return the name of the data object
            console.log("request url: ", data.url); // return the request url
            console.log("request parameters as objects: ", data.params); // return the remote request parameters as objects
            console.log("removte request with the params as get data: " + data.remoteUrl); // return the removte request with the params as get data
        }
    });*/
})();