XML Score Just One or two Team

Discussion in 'HTML & Website Design' started by asifadd38, Sep 12, 2013.

  1. #1
    Dear Programmer I am using this java script to get xml feed


    <script src="http://code.jquery.com/jquery-latest.js"></script>
    <script>
    var data;
    function requestForXml(site, callback) {
    var yql = 'http://query.yahooapis.com/v1/public/yql?q=' + encodeURIComponent('select * from xml where url="' + site + '"') + '&format=xml&callback=?';
    $.getJSON(yql, cbFunc);
    function cbFunc(data) {
    if (data.results[0]) {
    if (typeof callback === 'function') {
    callback(data);
    }
    }
    else throw new Error('getJSON returned null');
    }
    }
    function fin(data){
    var xmlDoc=data.results;
    var xmlData=StringtoXML(xmlDoc[0]);
    document.getElementById("finalCricScore").innerHTML="";
    $(xmlData).find('match').each(function(){
    var score = $(this).find('description').text();
    var head= $(this).find('header').text();
    var tex= $(this).find('url-text').text();
    var lin= $(this).find('url-link').text();
    document.getElementById("finalCricScore").innerHTML+=head+" "+score;
    document.getElementById("finalCricScore").innerHTML+="<br/>Status: "+tex;
    document.getElementById("finalCricScore").innerHTML+="<br/>";
    });
    }
    function StringtoXML(xmlintext){
    if (window.ActiveXObject){
    var doc=new ActiveXObject('Microsoft.XMLDOM');
    doc.async='false';
    doc.loadXML(xmlintext);
    } else {
    var xmlparser=new DOMParser();
    var doc=xmlparser.parseFromString(xmlintext,'text/xml');
    }
    return doc;
    }
    requestForXml("http://synd.cricbuzz.com/score-gadget/gadget-scores-feed.xml",fin);
    </script>
    This java script showing all team score... But I want to show one or two team score how Its possible..? have you any IDEA..? Thanks in Advance
     
    asifadd38, Sep 12, 2013 IP
  2. hdewantara

    hdewantara Well-Known Member

    Messages:
    538
    Likes Received:
    47
    Best Answers:
    25
    Trophy Points:
    155
    #2
    If you mean to show "just 2 matches" (not "just 2 teams") then perhaps you should change fin(data){}. The following some untested codes, but theoretically will limit the shows for the first 2 matches found (the change is in the use of "k" variable):
    $(xmlData).find('match').each(function(k){
    var score = $(this).find('description').text();
    var head= $(this).find('header').text();
    var tex= $(this).find('url-text').text();
    var lin= $(this).find('url-link').text();
    document.getElementById("finalCricScore").innerHTML+=head+" "+score;
    document.getElementById("finalCricScore").innerHTML+="<br/>Status: "+tex;
    document.getElementById("finalCricScore").innerHTML+="<br/>";
    if (k > 1) return false;
    });
    :)
     
    hdewantara, Sep 12, 2013 IP