Tuesday, April 3, 2012

XML PARSER in javascript, html and Samsung Smart tv development


This is an xml parsing function used in java, ajax, and html. The parameter that it needs is url but it should have extension xml like
 http://www.example.com.xml. The class or the .js file used here is Controller.js. For samsung Smart Tv Developers, if you want to
use it in scene.js, then you have to change the function to Scene.prototype.ParseXML = function (url)...
Controller.ParseXML = function (url) {
    alert("Controller.ParseXML()");
    this.arrayArticles = [];

    var count = 0;
    var _THIS_ = this;
    var count = 0;

    $.ajax({
           type: "get"
           ,dataType: "xml"
           ,url: url
           ,success: function(xml){
               if($(xml).find("item").length > 0){
                   $(xml).find("item").each(function(){ // loop
                       var t_title = $(this).find("title").text();
                       var t_description = $(this).find("description").text();

                       var oArticle = {};
                       oArticle.title = t_title;
                       oArticle.description = t_description;

                       _THIS_.arrayArticles.push(oArticle);

                     alert("<title>" + _THIS_.arrayArticles[count].title);
                       count++;
                   });
               }
           }
           ,error: function(){ alert("xml error!!"); }
    });
} 
If you have any queries feel free to comment.

No comments:

Post a Comment