【RSS】RSS格式详解Rss及Rss文件格式

By Heanny
2020-03-19
2200 read

简介

RSS是站点用来和其他站点之间共享内容的一种简易方式(也叫聚合内容),通常被用于新闻和博客等。一个RSS文件通常称为RSS Feed,其实也就是一个*.xml文件。

优点
不用一个网站一个网站,一个网页一个网页去逛了。只要这将你需要的内容订阅在一个RSS阅读器中,这些内容就会自动出现你的阅读器里,你也不必为了一个急切想知道的消息而不断的刷新网页,因为一旦有了更新,RSS阅读器就会通知你!

RSS文件内容
RSS文件内容包括:当前RSS站点的名称、URL地址、描述、使用的语言,及内容(内容里边有标题、URL、GUID-唯一标示符、描述、发布时间、作者等)。

RSS文件示例

<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:wfw="http://wellformedweb.org/CommentAPI/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:sy="http://purl.org/rss/1.0/modules/syndication/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/" version="2.0">
    <channel>
        <title>Heanny Blog RSS</title>
        <atom:link href="//www.heanny.cn/free" rel="self" type="application/rss+xml"/>
        <link>//www.heanny.cn/free</link>
        <description>
        我不是你的肖奈 | www.heanny.cn 个人博客分享,摄影分享,下载分享,VIP音乐下载,VIP视频破解 RSS
        </description>
        <language>zh-cn</language>
        <sy:updateFrequency>1</sy:updateFrequency>
        <sy:updatePeriod>hourly</sy:updatePeriod>
        <dc:rights>Copyright (C) heanny.cn. All rights reserved.</dc:rights>
        <generator>http://www.heanny.cn</generator>
        <item>
        <title>【html】referrer值的设置小记</title>
        <image>
        http://www.heanny.cn/update/blog/2003191404111584597851747230.jpeg
        </image>
        <link>http://www.heanny.cn/post-466.html</link>
        <guid>http://www.heanny.cn/post-466.html</guid>
        <description>
        ##html中的referrer值的设置当html页面中引入跨域的资源时(image,js,css等),可在html的heade……
        <br/>
        更多内容请点击“阅读原文”或复制“http://www.heanny.cn/post-466.html”到浏览器打开
        </description>
        <pubDate>2020-03-19 08:08:08</pubDate>
        <author>admin</author>
        </item>
  <channel>
</rss>

本站写动态生成RSS的代码

<?php
if (!defined('BASEPATH')) exit('No direct script access allowed');

/**
 * 2013-2-25:RSS订阅
 */
class Feed extends CI_Controller
{
    public function __construct()
    {
        parent::__construct();
        $this->load->model('feed_model');
        $this->load->helper('url_helper');
    }

    public function index()
    {
        $in_datas["xml_datas"] = array("it" => array(), "game" => array(), "blog" => array(), "movie" => array(), "book" => array());
        $this->_comm($in_datas);
    }

    public function rss()
    {
        $this->load->helper('xml');
        $this->load->helper('text');

        $in_datas["xml_datas"] = array('blog' => $this->feed_model->get_Blogs());
        $this->_comm($in_datas);

    }

    private function _comm($in_datas)
    {
        $in_datas['feed_name'] = "Heanny Blog RSS";
        $in_datas['feed_url'] = base_url() . "free";
        $in_datas['page_description'] = '我不是你的肖奈 | www.heanny.cn 个人博客分享,摄影分享,下载分享,VIP音乐下载,VIP视频破解 RSS';
        $in_datas['creator_email'] = 'lzh@heanny.cn';
        $in_datas['page_language'] = "zh-zn";
        $out_datas["xml"] = $this->write_rss($in_datas);
        header("Content-Type: text/xml");
        print_r($out_datas['xml']);
//        $this->load->view("rss",$out_datas);
    }
    public function write_rss($in_datas){
        $CI=& get_instance();
        $CI->load->helper('xml');
        $CI->load->helper('text');

        $xml_str="<?xml version='1.0' encoding='UTF-8'?>"
            ."<rss version='2.0' xmlns:content='http://purl.org/rss/1.0/modules/content/'  xmlns:wfw='http://wellformedweb.org/CommentAPI/' xmlns:dc='http://purl.org/dc/elements/1.1/' xmlns:atom='http://www.w3.org/2005/Atom' xmlns:sy='http://purl.org/rss/1.0/modules/syndication/'    xmlns:slash='http://purl.org/rss/1.0/modules/slash/'    >";
        if(!empty($in_datas)){
            $xml_str.="<channel>"
                ."<title>".$in_datas["feed_name"]."</title>"
                ."<atom:link href='".$in_datas["feed_url"]."' rel='self' type='application/rss+xml' />"
                ."<link>".$in_datas["feed_url"]."</link>"
                ."<description>".$in_datas["page_description"]."</description>"
                ."<language>zh-cn</language> "
                ."<sy:updateFrequency>1</sy:updateFrequency>"
                ."<sy:updatePeriod>hourly</sy:updatePeriod> "
                ."<dc:rights>Copyright (C) heanny.cn. All rights reserved.</dc:rights>"
                ."<generator>http://www.heanny.cn</generator>";
            if(!empty($in_datas["xml_datas"])){
                foreach($in_datas["xml_datas"] as $k => $v){
                    foreach($v as $xml){
                        $xml_str.=" <item>"
                            ."<title>".xml_convert($xml->title)."</title>"
                            ."<image>http://www.heanny.cn/update/blog/".$xml->img."</image>"
                            ."<link>http://www.heanny.cn/post-".$xml->id.".html</link>"
                            ."<guid>http://www.heanny.cn/post-".$xml->id.".html</guid>"
                            ."<description>".xml_convert(html_escape($xml->intro))."……<br/>\n更多内容请点击“阅读原文”或复制“http://www.heanny.cn/post-".$xml->id.".html”到浏览器打开</description>"
                            ."<pubDate>".$xml->time." 08:08:08</pubDate>  "
                            ."<author>$xml->user</author>"
                            ."</item>";
                    }
                }
            }
            $xml_str.="</channel>";

        }
        $xml_str.="</rss>";
        return $xml_str;
    }
}

格式

Rss文件格式
下面是一个Rss文件(*.xml),里面的注释是自己加的,之间为注释。

<?xml version="1.0" encoding="utf-8" ?>
<!-- 声明当前文件为xml文档【必】-->
    <rss version="2.0">
    <!-- 声明当前文件内容为rss格式文件,属性version(必须)指定当前rss版本【必】
    -->
    <channel>
    <!-- 固有节点【必】-->
        <title>Heanny Blog RSS</title>
        <!-- 网站标题【必】-->
        <image>
            <!-- 为当前RSS添加图片
            -->
            <title>img</title>
            <!-- 图片标题对图片的简单描述
            -->
            <link>//www.heanny.cn/free</link>
            <!-- 网站链接地址
            -->
            <url>//www.heanny.cn/free.jpg</url>
            <!-- 图片的链接地址    -->
        </image>
        <description>heanny blog rss feed</description>
        -<!-- 对当前RSS文件的描述【必】    -->
        <link>//www.heanny.cn</link>
        <!-- 网站主页链接【必】-->
        <language>zh-cn</language>
        <!-- 当前RSS使用的语言        -->
        <generator>www.heanny.cn</generator>
        <!-- 当RSS文件为自动创建时多存在此节点(RSS文件由什么创建)        -->
        <ttl>5</ttl>
        <!-- (ttl = time to live) 在刷新前当前RSS在cache中可以保存多长时间(分钟)        -->
        <copyright>Copyright © 2008-2020 www.heanny.cn. All rights reserved. </copyright>
        <!-- 声明版权        -->
        <pubDate>2020-03-18 01:45:05 GMT</pubDate>
        <!-- 当前RSS最后发布的时间        -->
        <category />
        <!-- 声明当前RSS内容的种类        -->
        <item>
        <!-- 一条信息        -->
            <title>【RSS】RSS格式详解Rss及Rss文件格式</title>
            <!-- 标题【必】
            -->
            <link>http://www.heanny.cn/post-468.html</link>
            <!-- 链接【必】
            -->
            <author>WWW.SINA.COM.CN</author>
            <!-- 作者
            -->
            <guid>http://www.heanny.cn/post-468.html</guid>
            <!-- guid>GUID=Globally Unique Identifier 为当前新闻指定一个全球唯一标示
            -->
            <category>blog</category>
            <!-- 种类
            -->
            <pubDate>2020 03-19 18:02:53 GMT</pubDate>
            <!-- 发布时间            -->
            <comments />
            <!-- 注释    -->
            <description>
##简介RSS是站点用来和其他站点之间共享内容的一种简易方式(也叫聚合内容),通常被用于新闻和博客等。一个RSS文件通常称为RS……
<br/>
更多内容请点击“阅读原文”或复制“http://www.heanny.cn/post-468.html”到浏览器打开
</description>
            <!-- 简单描述【必】            -->
        </item>
    </channel>
</rss>
【html】referrer值的设置小记
centos7初始化及安全问题

Comments

暂无评论,还不快来坐沙发...

Leave a Reply