ホーム HTML CSS XML JAVASCRIPT   PHP SQL MORE...   リファレンス 事例集    

RSS 構文


RSS 2.0 の構文規則は非常にシンプルで厳密です。


RSSの仕組み

RSSは、webサイト間でコンテンツを共有するために使用します。

RSSを使用して、アグリゲータと言う会社に内容を登録します。

従って、その一部であるために:まず、RSS 文書を作成し、.xml の拡張子で保存します。 その後、Web サイトにファイルをアップロードします。次に、RSSアグリゲータへ登録します。 毎日、アグリゲータはRSS文書の登録サイトを検索し、リンクを確認し、クライアントが興味 のある文書へリンクすることができるように、フィードに関する情報を表示します。

チップ: 無料の RSS アグリゲーションサービスを表示するために、「RSS フィードの公開」章を読んでください。


RSS 例

RSS文書は、自己記述と簡単な構文を使用します。

ここに簡単なRSSのドキュメントがあります:

<?xml version="1.0" encoding="ISO-8859-1" ?>
<rss version="2.0">

<channel>
  <title>W3Schools Home Page</title>
  <link>http://www.w3schools.com</link>
  <description>Free web building tutorials</description>
  <item>
    <title>RSS Tutorial</title>
    <link>http://www.w3schools.com/rss</link>
    <description>New RSS tutorial on W3Schools</description>
  </item>
  <item>
    <title>XML Tutorial</title>
    <link>http://www.w3schools.com/xml</link>
    <description>New XML tutorial on W3Schools</description>
  </item>
</channel>

</rss>

The first line in the document - the XML declaration - defines the XML version and the character encoding used in the document. In this case the document conforms to the 1.0 specification of XML and uses the ISO-8859-1 (Latin-1/West European) character set.

The next line is the RSS declaration which identifies that this is an RSS document (in this case, RSS version 2.0).

The next line contains the <channel> element. This element is used to describe the RSS feed.

The <channel> element has three required child elements:

  • <title> - Defines the title of the channel (e.g. W3Schools Home Page)
  • <link> - Defines the hyperlink to the channel (e.g. http://www.w3schools.com)
  • <description> - Describes the channel (e.g. Free web building tutorials)

Each <channel> element can have one or more <item> elements.

Each <item> element defines an article or "story" in the RSS feed.

The <item> element has three required child elements:

  • <title> - Defines the title of the item (e.g. RSS Tutorial)
  • <link> - Defines the hyperlink to the item (e.g. http://www.w3schools.com/rss)
  • <description> - Describes the item (e.g. New RSS tutorial on W3Schools)

Finally, the two last lines close the <channel> and <rss> elements.


Comments in RSS

The syntax for writing comments in RSS is similar to that of HTML:

<!-- This is an RSS comment -->


RSS is Written in XML

Because RSS is XML, keep in mind that:

  • All elements must have a closing tag
  • Elements are case sensitive
  • Elements must be properly nested
  • Attribute values must always be quoted