0
沒有什麼,甚至會,如果他們給我的項目數加載問題,我的RSS訂閱
這裏是代碼
var url = 'my url';
// loadRRSFeed(url) // is at the bottom of the js - after all the functions
// useful for getting rid of html links in text elements in a feed
Titanium.include('strip_tags.js');
///////////////////////////////////////////////////////
var rssWindow = Titanium.UI.createWindow({
title:'',
backgroundColor:'#fff'
});
var data;
var i = 0;
var feedTableView;
var feedTitle = '';
function displayItems(itemList){
for (var c=0;c < itemList.length;c++){
// Ti.API.info('item title :' + itemList.item(c).getElementsByTagName("title").item(0).text);
// Ti.API.info('item description :' + itemList.item(c).getElementsByTagName("description").item(0).text);
// Ti.API.info('item enclosure url :' + itemList.item(c).getElementsByTagName("enclosure").item(0).getAttribute("url"));
var title = null;
var desc = null;
//var mp3_url = null;
// If we want to only add items with mp3 enclosures
//if(itemList.item©.getElementsByTagName("enclosure")!=null){
// Item title
title = itemList.item(c).getElementsByTagName("TITRE").item(0).text;
// Item description
desc = itemList.item(c).getElementsByTagName("DESCRIPTION").item(0).text;
// Clean up any nasty linebreaks in the title and description
title = title.replace(/\n/gi, " ");
desc = desc.replace(/\n/gi, " ");
// Podcast mp3 enclosure
//mp3_url = itemList.item(c).getElementsByTagName("enclosure").item(0).getAttribute("url");
// Create a table row for this item
var row = Ti.UI.createTableViewRow({height:'auto',backgroundColor:'#eeeeee',selectedBackgroundColor:'#b40000'});
// Create a label for the title
var post_title = Ti.UI.createLabel({
text: title,
color: '#000',
textAlign:'left',
left:60,
height:'auto',
width:'auto',
top:3,
font:{fontWeight:'bold',fontSize:16}
});
row.add(post_title);
// add the CNN logo on the left
// naturally this could be an image in the feed itself if it existed
var item_image = Ti.UI.createImageView({
image:'My url image',
left:3,
top:2,
width:50,
height:34
});
row.add(item_image);
// Add some rowData for when it is clicked
row.thisTitle = title;
//row.thisMp3 = mp3_url;
row.thisDesc = desc;
// Add the row to the data
data[i] = row;
// I use 'i' here instead of 'c', as I'm only adding rows which have mp3 enclosures
i++;
} // end if enclosure
}
// create the table
feedTableView = Titanium.UI.createTableView({
data:data,
top:0,
width:320,
height:260
});
// Add the tableView to the current window
rssWindow.add(feedTableView);
// Create tableView row event listener
feedTableView.addEventListener('click', function(e){
// a feed item was clicked
Ti.API.info('item index clicked :'+e.index);
Ti.API.info('title :'+e.rowData.thisTitle);
Ti.API.info('desc :'+strip_tags(e.rowData.thisDesc));
//Ti.API.info('mp3 enclosure :'+e.rowData.thisMp3);
// show an alert
// Ti.UI.createAlertDialog({title:e.rowData.thisTitle, message:e.rowData.thisMp3}).show();
item_title_label.text = strip_tags(e.rowData.thisTitle);
item_desc_label.text = strip_tags(e.rowData.thisDesc);
// etc ...
// now do some cool stuff! :)
// like add an audio player, open a new window, etc..
//stream.stop();
//stream.url = e.rowData.thisMp3;
//stream.start();
});
//}
function loadRSSFeed(url){
data = [];
Ti.API.info('>>>> loading RSS feed '+url);
xhr = Titanium.Network.createHTTPClient();
xhr.open('GET',url);
xhr.onload = function()
{
Ti.API.info('>>> got the feed! ... ');
// Now parse the feed XML
var xml = this.responseXML;
// Find the channel element
var channel = xml.documentElement.getElementsByTagName("EPISODE");
feedTitle = channel.item(0).getElementsByTagName("TITRE").item(0).text;
Ti.API.info("FEED TITLE " + feedTitle);
rssWindow.title = feedTitle;
// Find the RSS feed 'items'
var itemList = xml.documentElement.getElementsByTagName("EPISODE");
Ti.API.info('found '+itemList.length+' items in the RSS feed');
//item_title_label.text = 'DONE';
//item_desc_label.text = 'click a feed item';
// Now add the items to a tableView
displayItems(itemList);
};
//item_title_label.text = 'LOADING RSS FEED..';
//item_desc_label.text = '';
xhr.send();
}
// load the feed
loadRSSFeed(url);
rssWindow.open();
你能幫助我請,這是迫切的,它仍然是隻要我有這個問題
謝謝
我的XML文件
<DATAS>
<EPISODES>
<EPISODE>
<ID>6712</ID>
<THEME>19</THEME>
<PROGRAMME>90</PROGRAMME>
<DATE_DEBUT>2011/04/25 12:05:00.0</DATE_DEBUT>
<DATE_FIN>2011/04/25 12:09:00.0</DATE_FIN>
<ALIAS></ALIAS>
<TITRE></TITRE>
<TITREPANELPREV></TITREPANELPREV>
<TITREPLAYER></TITREPLAYER>
<TITREPANELNEXT></TITREPANELNEXT>
<DESCRIPTION></DESCRIPTION>
<VIGNETTE>35.jpg</VIGNETTE>
<VIDEO>mp4:35</VIDEO>
<VIDEO_M>mp4:201104</VIDEO_M>
<CHAPITRES/>
</EPISODE><EPISODE>
<ID>6644</ID>
<THEME>16</THEME>
<PROGRAMME>125</PROGRAMME>
<DATE_DEBUT>2011/04/22 18:40:00.0</DATE_DEBUT>
<DATE_FIN>2011/04/22 18:44:00.0</DATE_FIN>
<ALIAS></ALIAS>
<TITRE></TITRE>
<TITREPANELPREV></TITREPANELPREV>
<TITREPLAYER></TITREPLAYER>
<TITREPANELNEXT></TITREPANELNEXT>
<DESCRIPTION></DESCRIPTION>
<VIGNETTE>2011.jpg</VIGNETTE>
<VIDEO>mp4:201104</VIDEO>
<VIDEO_M>mp4:3G.mp4/playlist.m3u8</VIDEO_M>
<CHAPITRES/>
…...etc
</DATAS>
Feed標題的標籤名稱是否真的帶有R的「TITRE」? – pjmorse 2011-04-26 13:47:24
感謝您的回答 是的,它是實際上我講法語[R 和我的應用程序是法國 我的XML文件中包含了太多的標籤,我只是把最重要的 – Sabrina 2011-04-26 14:18:09
顯示XML收到讓我們可以驗證你是否正確解析它。 (oh et francaise et codeuse ca fait plaisir ds ce monde d'anglophonehéhéhé) – john 2011-04-26 14:34:10