LoginSignup
15
13

More than 5 years have passed since last update.

最小限のAtomフォーマット

Last updated at Posted at 2012-02-24

最近、AtomをベースにしたXMLを書くことが多いので、必要最小限の要素をまとめてみる。意外と裏ルール(公式のスキーマファイルに記載されていない)が多くて正しいAtomを書くのは難しいです。

type=feed

atom:feedをルート要素にする場合。

  • entryはなくてもいい
  • id,title,updatedが必須。authorもentryが空っぽなら必須。
  • idはTag URIスキームを使うと短く書けるだろう。
  • authorはnameだけが必須。
  • link@selfはあった方がいいがMUSTではない。
feed.atom
<?xml version="1.0" encoding="UTF-8"?>
<feed xmlns="http://www.w3.org/2005/Atom">
  <id>tag:example.com,2012:1234</id>
  <title>sample feed</title>
  <updated>2012-01-01T00:00:00+09:00</updated>
  <link rel="self" href="http://example.com/self.atom"/>
  <author><name>author name</name></author>
</feed>

type=entry content埋め込み

atom:entryをルート要素にする場合、二通りある。ひとつはcontentを直接埋め込んでしまう方法。

  • id,title,updatedは必須。
  • authorもルートがentryになってしまうと必須。
  • contentはtypeを省略するとtextを内包しているとみなされる。 typeにXML系を指定する場合はcontentの子要素がそれ自身で完結したXMLでなくてはならない。即ちcontentの直下に含められる要素は一つだけである。
entry1.atom
<?xml version="1.0" encoding="UTF-8"?>
<entry xmlns="http://www.w3.org/2005/Atom">
  <id>tag:example.com,2012:1234</id>
  <title>sample entry</title>
  <updated>2012-01-01T00:00:00+09:00</updated>
  <author><name>author name</name></author>
  <content>コンテンツの中身そのもの</content>
</entry>

type=entry linkする

contentが文字で表しづらかったり、Web上に存在しないデータの場合はcontentに直接埋め込むのは不可能なので、linkを使って代替する情報を指定する。

  • contentを使わない場合はlink@rel=alternateが必須。
  • link@rel=alternateはrelを省略できる。
entry2.atom
<?xml version="1.0" encoding="UTF-8"?>
<entry xmlns="http://www.w3.org/2005/Atom">
  <id>tag:example.com,2012:1234</id>
  <title>sample entry</title>
  <updated>2012-01-01T00:00:00+09:00</updated>
  <author><name>author name</name></author>
  <link href="http://example.com/foo.html"/>
</entry>
15
13
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
15
13