Header Menu

OPML の仕様に関するまとめ

OPML先日、livedoor Reader 内、「おすすめフィード」 のコーナーに、当サイトも参加させていただいている AMN パートナーブログの OPML が掲載されたそうです。

で、告知だけだとあれなので、今回は OPML(Outline Processor Markup Language) について書いてみることに。というのも、OPML 自体はRSS リーダー等のサービス間でのデータ移動 (インポート、エクスポート) などを始め、ツールが生成したり、他の人が公開しているものを利用する側としてはかなり前から慣れ親しんでいるフォーマットですが、自分で書いて公開したことってほとんどなくて、その仕様なんかも詳しく調べたことなかかったことに気付き、いい機会なのでちょっと調べてみたというわけです。

OPML は新しいフォーマットではないので今さら感もありますが、いまいち情報が少ないので現時点でのまとめみたいになればいいなと思います。

まずは、今回参考にしたページを仕様関係から。

次に補助的な情報。

Opml.org の Spec ページを見ると 2007年の 11月付けで OPML 2.0 が最新の仕様として公開されていてそこで更新は止まっていますので、最新のバージョンとしては、OPML 2.0 ってことになると思います。上記のとおり、XML Schema も公開されています。

OPML 2.0 の Specification を見ると、「Subscription lists」 として、RSS をまとめて公開するための属性、及び属性値のフォーマットに関しての記述が追加されており、ここで outline 要素に対して xmlUrl 属性、htmlUrl 属性といった、現在多くの RSS リーダー等が対応している属性名が明確に定義されています。逆にいえば、OPML 1.0 ではこの辺の属性は定義されておらず、OPML 1.0 DTD では、

<!ELEMENT body (outline)+ >
<!ELEMENT outline (outline)* >
 
<!ENTITY % OtherAttributes  " "       >
<!ATTLIST outline
text CDATA #IMPLIED
type CDATA #IMPLIED
isComment (true|false) false
isBreakpoint (true|false) false
%OtherAttributes; >
<!--
text is the string of characters that's displayed when the outline is being browsed or edited. 
type is a string, it says how the other attributes of the <outline> are interpreted.
isComment indicates whether the outline is commented or not.
By convention if an outline is commented, all subordinate outlines are considered to be commented as well.
isBreakpoint indicates whether a breakpoint is set on this outline.This attribute is mainly necessary for outlines used to edit scripts that execute.
 
You can add whatever other attributes on the outline element you want.
-->

text、type、isComment、isBreakpoint の各属性のみ定義済みであとは自由に好きな属性を付け加えていいよとなっています。しかしその後、RSS のリストを公開するという用途での OPML 利用が広まったため、そこで使用されていた xmlUrl 属性、htmlUrl 属性などが明記されるようになったようです。

ということで、実際に OPML 2.0 を使用して フィードのリストをまとめて公開するための文書を作ってみましょう。OPML の仕様は簡単。まずはサンプルソースを下記に。

<?xml version="1.0" encoding="utf-8"?>
<opml version="2.0">
 <head>
  <title>mySubscriptions.opml</title>
  <dateCreated>Sat, 29 Mar 2008 12:11:52 +0900</dateCreated>
  <dateModified>Sun, 30 Mar 2008 21:42:48 +0900</dateModified>
  <ownerName>WWW WATCH</ownerName>
  <ownerEmail>example@example.com</ownerEmail>
  <ownerId>http://hyper-text.org/</ownerId>
 </head>
 <body>
  <outline text="My Blogs RSS Feed" title="My Blogs RSS Feed">
   <outline text="My Blog 1" title="My Blog 1" description="My sample blog 1" type="rss" language="ja" xmlUrl="http://example.com/rss/sample_1.xml" htmlUrl="http://example.com/sample1/" />
   <outline text="My Blog 2" title="My Blog 2" description="My sample blog 2" type="rss" language="ja" xmlUrl="http://example.com/rss/sample_2.xml" htmlUrl="http://example.com/sample2/" />
   <outline text="My Blog 3" title="My Blog 3" description="My sample blog 3" type="rss" language="ja" xmlUrl="http://example.com/rss/sample_3.xml" htmlUrl="http://example.com/sample3/" />
  </outline>
  <outline text="My Favorite Blogs RSS Feed" title="My Favorite Blogs RSS Feed">
   <outline text="My Favorite Blog 1" title="My Favorite Blog 1" description="My Favorite blog 1" type="rss" language="ja" xmlUrl="http://example.com/rss/favorite_1.xml" htmlUrl="http://example.com/favorite1/" />
   <outline text="My Favorite Blog 2" title="My Favorite Blog 2" description="My Favorite blog 2" type="rss" language="ja" xmlUrl="http://example.com/rss/favorite_2.xml" htmlUrl="http://example.com/favorite2/" />
   <outline text="My Favorite Blog 3" title="My Favorite Blog 3" description="My Favorite blog 3" type="rss" language="en" xmlUrl="http://example.com/rss/favorite_3.xml" htmlUrl="http://example.com/favorite3/" />
  </outline>
 </body>
</opml>

ルート要素は opml 要素になります。OPML 2.0 XML Schema を見ると、

<xs:complexType name="opmlType">
 <xs:annotation>
  <xs:documentation>version - is a number defining the edition of OPML used</xs:documentation>
 </xs:annotation>
 <xs:sequence>
  <xs:element name="head" type="headType" minOccurs="1" maxOccurs="1"/>
  <xs:element name="body" type="bodyType" minOccurs="1" maxOccurs="1"/>
 </xs:sequence>
 <xs:attribute name="version" type="versionType" use="required"/>
</xs:complexType>

となっていますので、opml 要素には version 属性が必須。また、opml 要素内には、head 要素、及び body 要素が 1つだけ必須になります。version は OPML 2.0 で書くなら、「version="2.0"」 と記述します。

次に head 要素を見てみましょう。

<xs:complexType name="headType">
 <xs:annotation>
  <xs:documentation>headType - contains zero or more of the optional elements defined below</xs:documentation>
  <xs:documentation>title - title or name of the document</xs:documentation>
  <xs:documentation>dateCreated - a date-time indicating when the document is created; conforms to RFC 822 (http://asg.web.cmu.edu/rfc/rfc822.html); see the Simple Types section for more information</xs:documentation>
  <xs:documentation>dateModified - a date-time indicating when the document has last modified; conforms to RFC 822 (http://asg.web.cmu.edu/rfc/rfc822.html); see the Simple Types section for more information</xs:documentation>
  <xs:documentation>ownerName - the owner of the document</xs:documentation>
  <xs:documentation>ownerEmail - the email address of the owner of the document; see the Simple Types section for more information</xs:documentation>
  <xs:documentation>ownerId - an http address of a web page that contains a form that allows a human reader to communicate with the author of the document via email or other means</xs:documentation>
  ...(中略)...
 </xs:annotation>
 
 <xs:sequence>
   <xs:element name="title" type="xs:string" minOccurs="0" maxOccurs="1"/>
   <xs:element name="dateCreated" type="rfc822Type" minOccurs="0" maxOccurs="1"/>
   <xs:element name="dateModifed" type="rfc822Type" minOccurs="0" maxOccurs="1"/>
   <xs:element name="ownerName" type="xs:string" minOccurs="0" maxOccurs="1"/>
   <xs:element name="ownerEmail" type="tEmailAddress" minOccurs="0" maxOccurs="1"/>
   <xs:element name="ownerId" type="xs:anyURI" minOccurs="0" maxOccurs="1"/>
  ...(中略)...
 </xs:sequence>
</xs:complexType>

head 要素内には、0個以上の要素が必要となっていますので、空でも問題ないのですが、タイトルとか制作者情報はここに記述します。要素名のままなので難しくはないと思いますが、dateCreated、dateModified 要素は、RFC 822 に従い記述する必要があるとなっています。RFC 822 はすでに破棄され RFC 2822 に取って代わられているのでちょっとここはイケてないんですが。

次に body 要素。

<xs:complexType name="bodyType">
 <xs:annotation>
  <xs:documentation>bodyType - contains one or more outline elements</xs:documentation>
  <xs:documentation>outline - the contents to be displayed; may contain encoded HMTL markup; see outlineType</xs:documentation>
 </xs:annotation>
 <xs:sequence>
  <xs:element name="outline" type="outlineWithTypeType" minOccurs="1" maxOccurs="unbounded"/>
 </xs:sequence>
</xs:complexType>

1つ以上の outline 要素が必須。で、outline 要素はというと、

<xs:complexType name="outlineType" mixed="true">
 <xs:annotation>
  <xs:documentation>text - the content to be displayed to users</xs:documentation>
  <xs:documentation>isComment - indicates whether the outline is commented or not; by convention if an outline is commented, then all subordinate outlines are considered commented</xs:documentation>
  <xs:documentation>isBreakpoint - indicates whether a breakpoint is set on this outline</xs:documentation>
  <xs:documentation>created - generation date-time of the outline node</xs:documentation>
  <xs:documentation>category - comma-separated, slash-delimited sets of strings</xs:documentation>
  <xs:documentation>description - the top-level description element from a feed</xs:documentation>
  <xs:documentation>url - an http address to display in a browser or a pointer an OPML file</xs:documentation>
  <xs:documentation>htmlUrl - the top-level link element from a feed; that is a feed attribute that tells a reader where the HTML version of the feed exists</xs:documentation>
  <xs:documentation>xmlUrl - the http address of the feed in XML</xs:documentation>
  <xs:documentation>title - the top-level title element from a feed</xs:documentation>
  <xs:documentation>version - the type of feed (e.g. RSS2, RSS1, etc.)</xs:documentation>
  <xs:documentation>language - the top-level language element from a feed</xs:documentation>
 </xs:annotation>
 
 <xs:attribute name="text" type="xs:string" use="required"/>
 <xs:attribute name="isComment" type="xs:boolean" use="optional" default="false"/>
 <xs:attribute name="isBreakpoint" type="xs:boolean" use="optional" default="false"/>
 <xs:attribute name="created" type="rfc822Type" use="optional"/>
 <xs:attribute name="category" type="xs:string" use="optional"/>
 <xs:attribute name="description" type="xs:string" use="optional"/>
 <xs:attribute name="url" type="xs:anyURI" use="optional"/>
 <xs:attribute name="htmlUrl" type="xs:anyURI" use="optional"/>
 <xs:attribute name="xmlUrl" type="xs:anyURI" use="optional"/>
 <xs:attribute name="title" type="xs:string" use="optional"/>
 <xs:attribute name="version" type="xs:string" use="optional"/>
 <xs:attribute name="language" type="union.languageType" use="optional"/>
</xs:complexType>

それから、上記に関連して type 属性の定義も、

<xs:attributeGroup name="typeAttribute">
  <xs:annotation>
   <xs:documentation>type - indicator of how the attributes on the outline element are to be interpreted</xs:documentation>
  </xs:annotation>
  <xs:attribute name="type" type="union.typeType" use="optional" default="text"/>
</xs:attributeGroup>

ながい、、ということで必須属性は text 属性。0個以上のオプション属性、テキストデータを持つことができ、0個以上の outline 要素を子要素として持つこともできます。(上記引用部分の下にて定義されてます。)

その他、RSS のまとめファイルとして OPML を使用する場合に outline 要素で使うことになるのが、

  • text 属性(必須属性)
  • type 属性
  • title 属性
  • xmlUrl 属性
  • htmlUrl 属性

あたりの属性。type 属性に 「rss」 とか 「atom」 記述、title 属性にフィードのタイトル、text 属性は必須なので title 属性と同じ値を。xmlUrl 属性にフィードの URI、htmlUrl 属性にサイトの URI を入れてあげれば OK って感じですね。そうすると上記のサンプル OPML みたいになります。

ちなみに、text 属性が必須になったのは OPML 2.0 からですので、OPML のバージョンを 「1.0」 で書くなら text 属性はいりません(何でもいいから属性が 1つ以上あれば OK)。それを踏まえて上記のサンプルを OPML 1.0 にした上で、要素や属性も削ってシンプルにするとこんな感じになります。

<?xml version="1.0" encoding="utf-8"?>
<opml version="1.0">
 <head>
  <title>mySubscriptions.opml</title>
  <dateCreated>Sat, 29 Mar 2008 12:11:52 +0900</dateCreated>
  <ownerName>WWW WATCH</ownerName>
 </head>
 <body>
  <outline title="My Blogs RSS Feed">
   <outline title="My Blog 1" type="rss" xmlUrl="http://example.com/rss/sample_1.xml" htmlUrl="http://example.com/sample1/" />
   <outline title="My Blog 2" type="rss" xmlUrl="http://example.com/rss/sample_2.xml" htmlUrl="http://example.com/sample2/" />
   <outline title="My Blog 3" type="rss" xmlUrl="http://example.com/rss/sample_3.xml" htmlUrl="http://example.com/sample3/" />
  </outline>
  <outline title="My Favorite Blogs RSS Feed">
   <outline title="My Favorite Blog 1" type="rss" xmlUrl="http://example.com/rss/favorite_1.xml" htmlUrl="http://example.com/favorite1/" />
   <outline title="My Favorite Blog 2" type="rss" xmlUrl="http://example.com/rss/favorite_2.xml" htmlUrl="http://example.com/favorite2/" />
   <outline title="My Favorite Blog 3" type="rss" xmlUrl="http://example.com/rss/favorite_3.xml" htmlUrl="http://example.com/favorite3/" />
  </outline>
 </body>
</opml>

で、最後に実際に OPML 2.0 で作ったファイルとしてウチの会社の社員ブログのフィードをまとめた OPML ファイルを上げておきます。

デジパ社員ブログフィード一覧 OPML

Add to Bookmarks
  • Hatenaブックマークに追加
  • del.icio.usに追加
  • POOKMARK Airlinesへ追加
  • livedoorクリップへ追加
  • ニフティクリップへ追加
  • Buzzurlにブックマーク
  • newsingへ投稿
  • Choixへ追加
  • Furlへ追加
  • Blinklistへ追加
  • Redditへ追加
Advertisement

comment & trackback

TRACKBACK URL : http://hyper-text.org/cms/mt-tb.cgi/455

trackback to this entry

... 0 trackback

comments

aetos, August 5, 2008 - 16:57.

はじめまして。
検索で引っかかったので参考にさせていただきました。

ところで、根拠とされている XML Schema(以下、DLESE版と呼ぶ)ですが、http://opml.org/spec2 で公開されている仕様(以下、Winer版と呼ぶ)とはかなり異なる部分があるようです。

・名前空間
Winer版は http://opml.org/spec2
DLESE版は http://www.dlese.org/Metadata/opml

・outline@type
Winer版は rss、link、include と、その他任意
Subscription List として使う場合は rss にすべきと思われるため、DLESE 版で rdf および atom とされている部分は rss とされるべきであろうと思います。
また、DLESE版では text/x-opml という値を取り得ますが、Winer 版では link または include とすべきであろうと思われます。

・outline@version
DLESE版は 1.0 または 2.0 とされていますが、Winer 版では RSS、RSS1 および scriptingNews とされています。また、Winer版では、Atom がどのような値なのか決められていないものの言及されており、これが "Atom" という値を取るであろう事は容易に想像されます。

なお、Winer版の仕様にはいくらかの混乱が見られることも指摘しておきます。
Winer自身の手による OPML Validator
http://www.opml.org/2005/10/28#a85
がありますが、OPML の仕様と Validator の仕様に矛盾がある部分があります(その場合は仕様の方が優先すると明言されてはいますが)。

・outline@type
仕様では任意の値を取り得ますが、Validator は既知の値でなければエラーになります。

・outline@version
仕様では RSS、RSS2、scriptingNews とされますが、validator はこれらに加えて RSS1 を許容します。なお、Atom はエラーとなります。

・その他の属性
仕様では、outline には任意の属性が認められますが、Validator では既知の属性以外はエラーとなります。

aetos, August 5, 2008 - 16:59.

間違えましたorz

outline@version は仕様では RSS、RSS1、scriptingNews ですが、Validator は加えて RSS2 も許容します。
でした。

aetos, August 5, 2008 - 17:09.

たびたび申し訳ありませんorz

DLESE 版の outline@version は 1.0 or 2.0 ではありませんでした。これは opml 自体のバージョンですね。
ただし、Winer 版には OPML 1.1 というのが存在します。
これは、head 内に cloud という要素を許容するものです。
が、これは 2.0 の仕様に含まれていないことから、2.0 では使えない要素かと思われます。

post your comment

comment form

* All Fields Required.

RSS Feed
  • Add to Google Reader
  • Add to My Yahoo
  • Add to netvibes
  • Subscribe in NewsGator Online
  • Subscribe in livedoor Reader
  • Subscribe in Hatena RSS Reader
  • Subscribe in Bloglines
  • Feed Count by FeedBurner