`
周凡杨
  • 浏览: 233256 次
  • 性别: Icon_minigender_1
  • 来自: 上海
社区版块
存档分类
最新评论

Rss 订阅 开发

阅读更多

 

              RSS Really Simple Syndication的缩写(对rss2.0而言,是这三个词的缩写,对rss1.0而言则是RDF Site Summary的缩写,1.02.0走的是两个体系)。

 

RSS 基于XML,所有的 RSS 必须遵循w3c网站上公布的XML 1.0 规范。

 

  在一个RSS文档中,根元素是<rss>,带有一个必备属性version,用以指明该文档遵循的rss规范,如果rss文档遵循本规范,则version值必须是2.0

 

  <rss>元素只有一个子元素,包含关于频道的一些信息。频道(channel)是整个blog,项(item)指一篇文章或日志(也有称这为post)

 

  

 

RSS2.0元素channel的子元素列表

 

     

 

元素(Element) 描述(Description) 重要性
title 频道名称 必备
link 频道的URL 必备
Description 频道的描述 必备
copyright 频道内容的版权说明 可选
pubDate 频道内容发布日期,格式遵循RFC822格式(年份可为2们或4位) 可选
category 指定频道所属的一个或几个类别 可选
generator 生成该频道的程序名 可选
docs 指向该RSS文件所用格式说明的URL 可选
cloud Allows processes to register with a cloud to be notified of updates to the channel, implementing a lightweight publish-subscribe protocol for RSS feeds. More info here. 可选
ttl 有效期,用以指明该频道可被缓存的最长时间 可选
image 指定一个 GIFJPEGPNG图片,用以与频道一起显示 可选
rating 这个频道的分级(主要指成人、限制、儿童等) 可选
textInput 指定一个text输入框供用户输入,具体信息及功能未定。 可选
skipHours 提示新闻聚合器,那些小时时段它可以跳过。 可选
skipDays 提示新闻聚合器,那些天它可以跳过。 可选

 

 

下面对其中我开发过程中遇到的问题进行整理:

 

知识1加样式不生效

 

<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0">
<channel>
<title>实体营业厅</title>
<link>http://www.sh.10086.cn</link>
<description />
     <item>
      <description><div><span style='color:blue;'>宝山</span><div style='float:left;widht:400px;'><span style='color:blue;>购机中心-通河路店</span><br/></div>        </description>
      <author />
     </item>
  </channel>
</rss>

 

   刚开始我在<description></description>节点中加的部分html代码,可通过浏览器(FireFox)无法看到样式生效后效果!看到的效果都是没有样式的!

 

在网上查了查,原来Firefox有这样个Bug---Feed View overrides XSLT stylesheet defined in XML documentFeed View overrides XSLT stylesheet defined in XML document

Firefox在看到一个URL的页面是XML后,会先扫描(scan/sniff)文档的前512个字节,如果发现有<rss<feed,就判断这是个feed文档,不理会自带的style,而直接使用Firefox的方式展现这个文档。所以,最快速和简单的解办法就是不让Firefox在文档的前512字节里看到<rss<feed。上述的Bug报告的反馈里,Firefox开发者就提到了这个Hack

The emerging workaround for this problem (which isn’t new to us, since we’re using the same heuristic that IE7 betas have been using for months) is to put in a comment ranting about the evils of sniffing web content and overriding the desires of web developers which is long enough to move "<rss" or "<feed" out of the first 512 bytes, since that’s all we sniff.

这就说明了新浪网的rss为什么能够在firefox中正确显示,因为在新浪网的rss文件中的开头部分都有一个很长的英文注释,如下:

 

<?xml version="1.0" encoding="utf-8"?>
<?xml-stylesheet type="text/xsl" title="XSL Formatting" href="/show_new_final.xsl" media="all"?>
<!--
SINA Corporation (NASDAQ: SINA) is a leading online media company and value-added information service (VAS) provider for China and for Chinese communities worldwide. With a branded network of localized websites targeting Greater China and overseas Chinese, SINA provides services through five major business lines including SINA.com (online news and content), SINA Mobile (mobile value-added services), SINA Online (community-based services and games), SINA.net (search and enterprise services) and SINA E-commerce (online shopping), offering Internet users and government and business clients an array of services including online media and entertainment, online fee-based VAS/wireless VAS, and e-commerce and enterprise e-solutions.
With 230 million registered users worldwide, 450 million daily page views and over 60 million active users for a variety of fee-based services, SINA is the most recognized Internet brand name in China and among Chinese communities globally.
In various surveys and polls, SINA has been recognized as the most valuable brand and the most popular website in China. For 2003 and 2005, SINA was ranked the "Most Preferred Website" in China according to the Chinese Academy of Social Sciences and considered "The Most Respected Chinese Company" for three consecutive years in 2003, 2004 and 2005 by the Economic Observer and the Management Case Study Center of Beijing University. At the same time, South China Weekend in both 2003 and 2004 honored SINA with the prestigious award of the "Chinese Language Medium of the Year."
-->
<rss version="2.0" >

 

  

 

这是最简单的办法,代价是512字节。Mozilla Developer Center也提出了另外两个方法,见Custom styles for RSS

 

 

而且可以通过添加xsl样式表的方式,来美化页面:

 

<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet type="text/xsl" title="XSL Formatting" href="/sh/rss/yyt_xsl.xsl" media="all"?>
<!--sh.10086.cn Corporation (NASDAQ: SH) is a leading online media company and value-added information service (VAS) provider for China and for Chinese communities worldwide. With a branded network of localized websites targeting Greater China and overseas Chinese, SINA provides services through five major business lines including SINA.com (online news and content), SINA Mobile (mobile value-added services), SINA Online (community-based services and games), SINA.net (search and enterprise services) and SINA E-commerce (online shopping), offering Internet users and government and business clients an array of services including online media and entertainment, online fee-based VAS/wireless VAS, and e-commerce and enterprise e-solutions.With 230 million registered users worldwide, 450 million daily page views and over 60 million active users for a variety of fee-based services, SINA is the most recognized Internet brand name in China and among Chinese communities globally.In various surveys and polls, SINA has been recognized as the most valuable brand and the most popular website in China. For 2003 and 2005, SINA was ranked the "Most Preferred Website" in China according to the Chinese Academy of Social Sciences and considered "The Most Respected Chinese Company" for three consecutive years in 2003, 2004 and 2005 by the Economic Observer and the Management Case Study Center of Beijing University. At the same time, South China Weekend in both 2003 and 2004 honored SH with the prestigious award of the Chinese Language Medium of the Year.-->
<rss version="2.0">
<channel>
<title><![CDATA[实体营业厅]]></title>
<link><![CDATA[http://www.sh.10086.cn]]></link>
<description />

<item>
<value><![CDATA[1]]></value>
<title><![CDATA[购机中心-通河路店]]></title>
<address><![CDATA[通河路286--290号]]></address>
<time><![CDATA[9:00--20:30]]></time>
<code><![CDATA[]]></code>
<phone><![CDATA[18621880223]]></phone>
<busitype><![CDATA[基础业务]]></busitype>
<quyu><![CDATA[宝山]]></quyu>
<description><![CDATA[<div style="background-color:#eeeeee;width:280px;height:180px;float:left;margin-left:10px;text-align:left;margin-top:20px;padding:20px;"><div style="margin-top:6px;"><span style="color:blue;"><b>购机中心-通河路店</b></span></div><div style="margin-top:6px;"><span><b>地          址:</b></span>通河路286--290号</span></div><div style="margin-top:6px;"><span><b>营业时间:</b></span>9:00--20:30</span></div><div style="margin-top:6px;"><span><b>邮政编码:</b></span></span></div><div style="margin-top:6px;"><span><b>联系电话:</b></span>18621880223</span></div><div style="margin-top:6px;"><span><b>业务受理种类:</b></span>基础业务</span></div><div style="margin-top:6px;"><span><b>区          域:</b></span>宝山</span></div></div>]]></description>
<link>http://www.sh.10086.cn?t=136609478033110793212516461462</link>
</item>

<item>
<value><![CDATA[0]]></value>
<title><![CDATA[宝山营业厅]]></title>
<address><![CDATA[牡丹江路1512号]]></address>
<time><![CDATA[9:00-19:00]]></time>
<code><![CDATA[201900]]></code>
<phone><![CDATA[13916710080]]></phone>
<busitype><![CDATA[基础业务]]></busitype>
<quyu><![CDATA[宝山]]></quyu>
<description><![CDATA[<div style="background-color:#eeeeee;width:280px;height:180px;float:left;margin-left:10px;text-align:left;margin-top:20px;padding:20px;"><div style="margin-top:6px;"><span style="color:blue;"><b>宝山营业厅</b></span></div><div style="margin-top:6px;"><span><b>地          址:</b></span>牡丹江路1512号</span></div><div style="margin-top:6px;"><span><b>营业时间:</b></span>9:00-19:00</span></div><div style="margin-top:6px;"><span><b>邮政编码:</b></span>201900</span></div><div style="margin-top:6px;"><span><b>联系电话:</b></span>13916710080</span></div><div style="margin-top:6px;"><span><b>业务受理种类:</b></span>基础业务</span></div><div style="margin-top:6px;"><span><b>区          域:</b></span>宝山</span></div></div>]]></description>
<link>http://www.sh.10086.cn?t=136609478033110793212516489061</link>
</item>
</channel>
</rss>

 

  

Yyt_xsl.xsl

 

<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="2.0">
<xsl:template match="/">
<html>
<head>
<title>
RSS-<xsl:value-of select="rss/channel/title"/>
</title>
</head>
<body>
<center>
<xsl:apply-templates select="rss/channel"/>
</center>
</body>
</html>

</xsl:template>
<xsl:template match="channel">
<xsl:for-each select="item">  
         <xsl:variable name="v">
              <xsl:value-of select="value"/> 
          </xsl:variable>
        <xsl:if test="$v &gt; 0">
        <div style="clear:both;color:blue;font-size:28px;margin-top:10px 0;font-weight:bold;text-align:left;padding-left:30px;"><xsl:value-of select="quyu"/> </div>
       </xsl:if>

    <div style="background-color:#eeeeee;width:280px;height:180px;float:left;margin-left:10px;text-align:left;margin-top:20px;padding:20px;">
        <div style="margin-top:6px;"><span style="color:blue;"><b><xsl:value-of select="title"/></b></span>      </div>
        <div style="margin-top:6px;"><span ><b>地          址:</b></span><xsl:value-of select="address"/>     </div>
        <div style="margin-top:6px;"><span><b>营业时间:</b></span><xsl:value-of select="time"/>        </div>
        <div style="margin-top:6px;"><span><b>邮政编码:</b></span><xsl:value-of select="code"/>          </div>
        <div style="margin-top:6px;"><span><b>联系电话:</b></span><xsl:value-of select="phone"/>             </div>
        <div style="margin-top:6px;"><span><b>业务受理种类:</b></span><xsl:value-of select="busitype"/>     </div>
        <div style="margin-top:6px;"><span><b>区          域:</b></span><xsl:value-of select="quyu"/>               </div>
      </div>
</xsl:for-each>
</xsl:template>
</xsl:stylesheet>

 知识点2

  Rss阅读器只检测到一个item中的内容,即只显示一个item里的内容,但item是有多个的!

  原因: <item></item>节点中的<link></link>值不能有重复,如果值相同,则只会显示一个item

 

 

 

参考资料:

        https://bugzilla.mozilla.org/show_bug.cgi?id=338621#c1

http://www.25175.com/200609/25175/25175_html/2007-04/1598.html

http://hi.baidu.com/yisqiu/item/5adb4f21c8855c3394f62b1e

0
1
分享到:
评论

相关推荐

    RSS订阅器(JAVA)

    以上就是关于"RSS订阅器(JAVA)"的知识点,这个项目不仅涉及到RSS的使用,还涵盖了JAVA编程、Spring MVC框架的应用,以及Web开发的诸多方面。对于学习和提升JAVA Web开发技能来说,这是一个很好的实践项目。

    使用RSS订阅喜欢的bilibiliup主和番剧

    在这个场景中,我们关注的是如何利用RSS订阅B站(哔哩哔哩,bilibili)上的UP主(内容创作者)和番剧(动画系列)。"bilibili2RSS-master"这个压缩包文件很可能包含了一个项目或脚本,旨在帮助用户将B站的内容转化为...

    C#自己做的RSS订阅器

    标题中的"C#自己做的RSS订阅器"表明这是一个使用C#编程语言开发的程序,用于处理RSS(Really Simple Syndication)订阅。RSS是一种XML格式,它允许用户订阅网站更新,如新闻、博客文章或其他定期发布的在线内容,而...

    rss 订阅

    **RSS订阅**是一种在线内容发布和聚合机制,它允许用户订阅感兴趣的网站或博客的更新,无需直接访问每个站点。RSS(Really Simple Syndication)是一种XML格式,用于分享新闻、文章和其他内容。通过RSS订阅,用户...

    ASP.NET RSS订阅

    ASP.NET RSS订阅是一种常见的Web应用程序开发技术,用于创建和分发新闻和其他定期更新的内容。RSS,全称Really Simple Syndication,是一种XML格式,允许用户通过RSS阅读器或聚合器订阅和获取网站的最新内容,无需...

    C# RSS阅读器 能添加和阅读订阅

    RSS订阅者可以使用RSS阅读器或新闻聚合器来订阅这些源,以便在有新内容发布时得到通知。C# RSS阅读器就是这样一个工具,它可以连接到用户指定的RSS网址,自动下载并解析feed,然后显示其中的文章。 在C#中实现RSS...

    猎犬RSS订阅源系统 Ver 2.0

    【猎犬RSS订阅源系统 Ver 2.0】是一个基于Visual Basic(VB)开发的软件,主要用于客户端阅读和管理RSS(Really Simple Syndication)、XML和ATOM格式的新闻信息。这个系统设计精巧,无需依赖额外的OCX或DLL组件,...

    网站RSS订阅功能插件RSSMaker JSP版 v1.0

    RSSMaker是一款专为网站设计的RSS订阅功能插件,由雅客网(iRSSer.com)自主开发,旨在帮助网站快速、方便地为用户提供RSS订阅服务。 **RSS订阅的工作原理** RSS订阅的核心在于XML格式的RSS feed,它包含网站的标题...

    JSP-RSS订阅,网站插件订阅,源码.zip

    【标题】"JSP-RSS订阅,网站插件订阅,源码.zip" 涉及的知识点主要集中在Java服务器页面(JSP)、RSS订阅技术以及网站插件开发方面。这是一份基于Java技术的毕业设计项目,旨在实现一个能够帮助用户订阅并管理RSS源...

    flex写的rss订阅程序

    在Flex中开发RSS订阅程序,通常会用到以下关键技术: 1. **Flex SDK**:Flex SDK是Adobe提供的免费开源工具包,用于创建富互联网应用程序(RIA)。它包括ActionScript编译器、Flex框架库和MXML编译器,这些工具使...

    RSS订阅频道管理模块

    通过学习和实践这个RSS订阅频道管理模块,初级开发人员可以提升对C#、ASP.NET和.NET框架的理解,同时掌握Web应用开发的基本流程和技巧。此外,还可以进一步研究如何使用现代前端框架(如React或Vue.js)来增强用户...

    php的rss订阅功能实现包

    为了使RSS订阅功能正常工作,你需要确保生成的XML符合RSS 2.0或更早版本的标准。这些标准定义了如何组织和标记数据,以便RSS阅读器能够正确解析和显示内容。在`feed.php`中,你可能还会发现一些预定义的PHP函数,如`...

    基于jsp技术的RSS订阅系统

    【基于jsp技术的RSS订阅系统】是一个以JavaServer Pages(JSP)为核心开发的Web应用程序,主要用于实现RSS(Really Simple Syndication)新闻的订阅和定时更新功能。RSS是一种内容发布和聚合的格式,使得用户无需...

    RSS 订阅功能

    为 .NET web 版的 一个 RSS 订阅功能 ,链接 ACCESS 数据库 ,显示更新的 产品、新闻、展会等信息。可订阅到网易、QQ空间等。也可订阅到浏览器。功能简单 ,易懂。重点是代码,逻辑。

    Android Rss订阅源码Demo.zip

    这个"Android Rss订阅源码Demo.zip"是一个实用的示例项目,可以帮助开发者了解如何在Android应用中实现RSS订阅功能。 1. **RSS基础概念**: RSS是一种XML格式,用于发布和共享信息,通常用于博客、新闻站点等。它...

    AntennaPod支持rss订阅、音乐订阅

    AntennaPod是一款专为Android平台设计的开源播客(Podcast)应用,它以其强大的RSS订阅功能和音乐订阅服务而受到用户的青睐。在本文中,我们将深入探讨AntennaPod的核心特性,以及如何利用这些功能来优化你的音频...

    网站RSS订阅功能插件RSSMaker ASP.net版_aspx开发教程.rar

    网站RSS订阅功能插件RSSMaker ASP.NET版是一个用于在ASP.NET平台上实现RSS订阅功能的工具。RSS(Really Simple Syndication)是一种数据格式,允许用户通过RSS阅读器或聚合器获取网站更新,无需直接访问网站。...

    Android源码——Rss订阅源码Demo.7z

    《Android源码解析:Rss订阅源码Demo》 在移动开发领域,Android以其开源、灵活的特性,深受开发者喜爱。对于许多应用来说,实时获取并展示新闻资讯是必不可少的功能,而RSS(Really Simple Syndication)订阅就是...

    servelet实现的Rss订阅

    在这个场景中,我们将讨论如何使用Servlet来实现RSS订阅功能,并生成XML文件。 首先,理解RSS的基本结构至关重要。RSS文件通常是一个XML文档,包含一系列频道(channel)和条目(item)。频道包含了有关整个源的...

Global site tag (gtag.js) - Google Analytics