본문으로 바로가기

JQUERY XML 파싱

category Programming/Etc 2010. 12. 29. 10:17
    var texts = '';
    $.ajax({
        type: "get"
       ,dataType: "xml"
       ,url: "./keyword.xml"
       ,success: function(xml){
           for(i=1; i<=5; i++){
              var id = $(xml).find("Query[id='"+i+"']").attr("id");
              var title = $(xml).find("Query[id='"+i+"']").attr("word");
              var updown = $(xml).find("Query[id='"+i+"']").attr("updown");
              if(updown == "u"){
                  updown = "<img src=images/upic.jpg width=7 height=8 />";
              }else if(updown == 'd'){
                  updown = "<img src=images/downic.jpg width=7 height=8 />";
              }else if(updown == 'c'){
                  updown = "-";
              }else if(updown == 'n'){
                  updown = "<img src=images/newic.jpg />";
              }
              texts += "<table border=0 width=100%>";
              texts += "<tr><td width=7% align=left>"+ id + "</td>";
              texts += "<td width=80% height=21 align=left>"+ title + "</td>";
              texts += "<td width=80% height=21 align=left>"+ updown + "</td></tr>";
              texts += "</table>";
           }
           $("#bskeyword").html(texts);
        }
        ,error: function(){ alert("xml error!!"); }
     });