Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <!DOCTYPE html>
- <html>
- <head>
- <meta charset="UTF-8" /><title>rss受信テスト</title>
- <script src='https://code.jquery.com/jquery-2.1.4.min.js'></script>
- <script>
- $.ajax({
- url: 'http://rfobasic.freeforums.org/feed.php',
- type: 'get',
- dataType: 'xml',
- timeout: 5000,
- success: function(xml, status) {
- if (status === 'success') {
- // alert('bbb');
- var row = 0;
- var data = [];
- var nodeName;
- var hizuke = [];
- var aaa = '';
- // alert('ccc');
- $(xml).find('item').each(function() {
- // alert('ccd');
- data[row] = {};
- $(this).children().each(function() { // 子要素を取得
- nodeName = $(this)[0].nodeName; // 要素名
- data[row][nodeName] = {}; // 初期化
- attributes = $(this)[0].attributes; // 属性を取得
- for (var i in attributes) {
- data[row][nodeName][attributes[i].name] = attributes[i].value; // 属性名 = 値
- console.log(row,nodeName,attributes[i].name);
- console.log(data[row][nodeName][attributes[i].name]);
- }
- if (nodeName == "dc:date") {
- //alert('aaa');
- hizuke[row] = $(this).text();
- }
- if (nodeName == "pubDate") {
- //alert('aaa');
- hizuke[row] = $(this).text();
- }
- data[row][nodeName]['text'] = $(this).text();
- // alert(row,' ',nodeName,' ',attributes[i].name);
- // console.log(row,' ',nodeName,' ',attributes[i].name);
- // console.log(data[row][nodeName]['text']);
- });
- row++;
- });
- $('#rss').wrapInner('<ul></ul>');
- for (i in data) {
- $('#rss').find('ul').append('<li>' + data[i].title.text + '</li>');
- }
- for (i in data) {
- aaa = aaa + data[i].title.text;
- aaa = aaa + '@x@';
- aaa = aaa + data[i].link.text;
- aaa = aaa + '@x@';
- aaa = aaa + '【@feedname@】';
- aaa = aaa + '@x@';
- aaa = aaa + $('<div>').html(data[i].description.text).text();
- aaa = aaa + '@x@';
- aaa = aaa + hizuke[i];
- aaa = aaa + '@y@';
- //console.log(data[i].link.text);
- //console.log(data[i].title.text);
- // console.log(data[i].description.text);
- // console.log(data[i].description.text.replace(/<("[^"]*"|'[^']*'|[^'">])*>/g,''));
- //console.log($('<div>').html(data[i].description.text).text());
- // console.log(data[i].pubDate.text);
- // console.log(data[i].dc\\:date.text);
- //console.log(hizuke[i]);
- }
- alert(aaa);
- }
- }
- });
- </script>
- </head>
- <body>
- <div id="rss"></div>
- </body>
- </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement