その9

実際動いているサイトはこちら

plaza.jsの解説(続き)

 今回は、displayresultsファンクションを掲載。解説は次回からということで…。

検索結果表示・共通処理
function displayresults(shop,xml) {
    ResultsDiv[shop].innerHTML = "";
    items = xml.getElementsByTagName('Item');
    buf = "";
    if(items.length>=0) {
        KeywordNode    = xml.getElementsByTagName('Keyword');
        Keyword        = KeywordNode[0].childNodes[0].nodeValue;
        WebURLNode     = xml.getElementsByTagName('WebURL');
        WebURL         = WebURLNode[0].childNodes[0].nodeValue;
        TotalCountNode = xml.getElementsByTagName('TotalCount');
        TotalCount     = TotalCountNode[0].childNodes[0].nodeValue;
        CountNode      = xml.getElementsByTagName('Count');
        Count          = CountNode[0].childNodes[0].nodeValue;

        InfoDiv[shop].innerHTML = '<hr /><p><strong><span style="color : #0000FF;">' + ShopName[shop] + '「' + Keyword + '」の 検索結果</span> ' + TotalCount + ' 件中 ' + Count + ' 件表示</p><p>(全件表示されていない場合は、<a href="' + WebURL + '">こちら</a>からご覧いただけます)</strong></p><hr />\n';

        buf += '<table style="width : 95%; margin : 0em auto 1em auto; font-size : 100%;" summary="' + shop.toUpperCase + ' RESULT" border="0" cellspacing="0" cellpadding="0"><tbody>\n';
        for(i=0;i<items.length;i++) {
            RowNumNode            = items[i].getElementsByTagName('RowNum');
            URLNode               = items[i].getElementsByTagName('URL');
            TitleNode             = items[i].getElementsByTagName('Title');
            ImageURLNode          = items[i].getElementsByTagName('ImageURL');
            FormattedPriceNode    = items[i].getElementsByTagName('FormattedPrice');
            RowNum                = RowNumNode[0].childNodes[0].nodeValue;
            URL                   = URLNode[0].childNodes[0].nodeValue;
            Title                 = TitleNode[0].childNodes[0].nodeValue;
            ImageURL              = ImageURLNode[0].childNodes[0].nodeValue;
            TypeImageURL          = "";
            Type                  = "";
            FormattedPrice        = "";
            NewFormattedPrice     = "";

            if(FormattedPriceNode[0].childNodes.length>0) {
                FormattedPrice    = FormattedPriceNode[0].childNodes[0].nodeValue;
            }

            if(shop=="amazon") {
                NewFormattedPriceNode = items[i].getElementsByTagName('NewFormattedPrice');
                if(NewFormattedPriceNode[0].childNodes.length>0) {
                    NewFormattedPrice = NewFormattedPriceNode[0].childNodes[0].nodeValue;
                }
            }
            else
            if(shop=="bidders") {
                TypeImageURLNode      = items[i].getElementsByTagName('TypeImageURL');
                TypeNode              = items[i].getElementsByTagName('Type');
                TypeImageURL          = TypeImageURLNode[0].childNodes[0].nodeValue;
                Type                  = TypeNode[0].childNodes[0].nodeValue;
            }

            if(NewFormattedPrice==""
            && Type             ==""
            && shop             !="storemix") {
                buf += '<tr><td><p>' + RowNum + '</p></td><td style="text-align : center;"><p><a href="' + URL + '"><img src="' + ImageURL + '" alt="' + Title + '" /></a></p></td><td><p><a href="' + URL + '">' + Title + '</a></p></td><td><p style="text-align : right;">' + FormattedPrice + '</p></td></tr><tr><td colspan="4"><p style="text-align : right; font-size : 80%;"><a href="#top">ページのトップへ</a></p><hr class="thin"/></td></tr>\n';
            }
            else
            if(shop             =="storemix") {
                buf += '<tr><td><p>' + RowNum + '</p></td><td style="text-align : center;"><p><a href="' + URL + '"><img src="' + ImageURL + '" width="64" alt="' + Title + '" /></a></p></td><td><p><a href="' + URL + '">' + Title + '</a></p></td><td><p style="text-align : right;">' + FormattedPrice + '</p></td></tr><tr><td colspan="4"><p style="text-align : right; font-size : 80%;"><a href="#top">ページのトップへ</a></p><hr class="thin"/></td></tr>\n';
            }
            else
            if(NewFormattedPrice=="") {
                buf += '<tr><td><p>' + RowNum + '</p></td><td style="text-align : center;"><p><a href="' + URL + '"><img src="' + ImageURL + '" width="64" alt="' + Title + '" /></a></p></td><td><p><a href="' + URL + '">' + Title + '</a></p></td><td><p style="text-align : right;"><img src="' + TypeImageURL + '" alt="' + Type + '" /><br/>' + FormattedPrice + '</p></td></tr><tr><td colspan="4"><p style="text-align : right; font-size : 80%;"><a href="#top">ページのトップへ</a></p><hr class="thin"/></td></tr>\n';
            }
            else
            if(Type             =="") {
                buf += '<tr><td><p>' + RowNum + '</p></td><td style="text-align : center;"><p><a href="' + URL + '"><img src="' + ImageURL + '" alt="' + Title + '" /></a></p></td><td><p><a href="' + URL + '">' + Title + '</a></p></td><td><p style="text-align : right;">' + FormattedPrice + '<br/> =&gt; <strong style="color : #FF0000;">' + NewFormattedPrice + '</strong></p></td></tr><tr><td colspan="4"><p style="text-align : right; font-size : 80%;"><a href="#top">ページのトップへ</a></p><hr class="thin"/></td></tr>\n';
            }
        }
        buf += '</tbody></table>\n';
    }
    ResultsDiv[shop].innerHTML   = buf;

    BookmarksDiv[shop].innerHTML = '<p><a href="#' + shop + 'info"><strong>' + ShopName[shop] + ' の検索結果へ</strong></a></p>';

    ErrMsgNode = xml.getElementsByTagName('ErrMsg');
    if(ErrMsgNode[0].childNodes.length>0) {
        ErrorDiv[shop].innerHTML = '<p><strong style="color : #FF0000;">' + ErrMsgNode[0].childNodes[0].nodeValue + '</strong></p>';
    }
    else {
        ErrorDiv[shop].innerHTML = '';
    }
}