×
Namespaces

Variants
Actions
Revision as of 13:25, 9 May 2013 by hamishwillee (Talk | contribs)

(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)

解决WDE向导生成News应用中有些中文RSS内容不能显示的问题

From Nokia Developer Wiki
Jump to: navigation, search

Delete instructional text in italic

This article explains how to ... Replace the abstract text with a short paragraph (or sentence) describing what the topic covers.

Enter article metadata as described below. Note that this template can be placed anywhere in the article. Do not remove parameters that you do not use

Article Metadata
Article
Created: (
Error creating thumbnail: Image type not supported
)
Last edited: hamishwillee (09 May 2013)

Contents

Introduction

为用户提供能浏览大部分主流网站的RSS内容的Web app是非常重要的,国内外的绝大部分主流网站都提供了RSS订阅服务。

问题

在我们使用WDE的向导生成一个News Web app project后,如图所示:
News Wizard.png
我们可以得到一个解析RSS Feeds内容并显示的例子程序,但是,当将定义在index.html中的链接替换为其他RSS Feeds比如Sina链接时:如:新浪体育,例子程序显示内容不成功。

分析

打开这些RSS Feeds并浏览源码,发现这些RSS的内容是符合RSS技术标准的,返回的数据是xml格式。 分析自动生成的代码我们发现,jquery.jfeed.js中的解析函数先对返回的Head数据包进行解析,如果返回的Head数据的 content-type为“text.xml”则继续解析其responseText, 否则退出。跟踪Sina的Rss Feeds,发现返回的content-type是“application/xml”,所以解析函数没有继续解析返回的数据,造成应用不能正确显示RSS Feeds内容的结果。

解决

解决办法是将jquery.jfeed.js 文件中的第54行即:if(arr[0].toLowerCase() == "text/xml”){ 改为: if(arr[0].toLowerCase() == "text/xml"||"application/xml"){ ,代码如下:

   if(options.url) {
......
if (xhr.status == 200) {
var header = xhr.getResponseHeader("Content-Type");
var arr = header.split(';');
if(arr[0] == null || arr[0] == "")
return;
console.log(header);
if(arr[0].toLowerCase() == "text/xml"||"application/xml"){ //返回的内容类型为“application/xml”
if (xhr.responseText != null) {
var feed = new JFeed(xhr.responseXML);
if(jQuery.isFunction(options.success)) options.success(feed);
......
};

解决之后经测试如下中文RSS Feeds都能正常显示。
1, 腾讯IT频道
2, 新浪体育
3, 奶味网
4, 搜狐新闻

相关链接

Add categories below. Remove Category:Draft when the page is complete or near complete

This page was last modified on 9 May 2013, at 13:25.
103 page views in the last 30 days.

Was this page helpful?

Your feedback about this content is important. Let us know what you think.

 

Thank you!

We appreciate your feedback.

×