1)名譽和巨大的財富
設想一個從最熱門的門戶網站獲得最新的新聞的站點。股票價格,天氣信息,新聞故事,線式討論組,軟件發布……所有這一切都將被動態更新,每小時一次,不需要任何手工干預。我們可以想象這隨之而來的站點訪問量,源源不斷的廣告收入以及網管大人所受到的“阿諛奉承”。
但是現在,停止幻想,開始閱讀,因為只要你密切關注此項技術,說不定你就能成為站點的主人。 對你的要求也只是稍許的想象力,一些聰明的php編碼和幾個免費的rss文件。另外,很明顯還包括這篇文章剩下的九個部分。
2)有內容,就聯合成辛迪加(have content, will syndicate)
我們從最基本的開始——那么rss究竟是什么鬼東西呢?
rss(即rdf site summary)是一種格式,最早由netscape公司設計,用于分發其門戶站點my.netscape.com上的內容的描述信息。自1997年被提出以來,幾經沉浮——可以點擊文章末尾的鏈接,了解一下rss悠久復雜的歷史。現在的穩定的版本是rss1.0,符合rdf規范。這一版本可以說即輕便又功能齊全。
rss使得網管及時公布和分發某一特定站點的特定位置的最新最有趣的內容的描述信息變的可能。 從新聞文章列表到股票市場數據或著是天氣預報,所有這些信息都可以通過結構良好的xml文檔來發布,從而也可以被任何xml分析器進行分析,處理和翻譯。
網站上最新信息的列表是經常更新的,而rss使得這一列表的分發成為可能,也就為web上簡易的內容辛迪加聯合打開了大門。想了解這其中的道理,請看下面這個簡單的例子:
站點a,屬新聞站點(“內容辛迪加組織者”),能夠每小時發布一個包含最新新聞列表以及相應鏈接的rss文檔。 而這一rss文檔可以被其它站點獲?。ㄈ缯军cb,“內容收集者”),分析并顯示在站點b的索引頁面上。 每次站點a發布一個新的rss文檔,站點b的索引頁面都可以自動更新,以獲取最新的新聞。
這種方案對交易中的雙方機構都有效。 既然rss文檔中的鏈接都指向站點a上相應的文章,那么站點a將迅速體驗到訪問量的增加。 而站點b的網管可以休假一個星期,因為他有辦法自動更新其站點上的索引頁面,而這一方法僅僅是把索引頁面與站點a發布的動態內容相連接而已。
有許多受歡迎的站點向公眾提供詳細的rss或rdf新聞,如freshmeat(http://www.freshmeat.net)和slashdot(http://www.slashdot.org),當然還有其它許多站點。在這篇文章當中,我將廣泛的使用freshmeat網站的rdf文件。需要說明的一點是,這里所談到的技術也可以應用于其它任何rss1.0或rdf文件。
3)交換頻道(switching channels)
典型的rss文檔包含一個由描述性元數據標記出來的資源列表(urls),請看下面的例子:
<?xml version="1.0" encoding="utf-8"?>
<rdf:rdf xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
xmlns="http://purl.org/rss/1.0/">
<channel rdf:about="http://www.melonfire.com/">
<title>trog</title>
<description>well-written technical articles and
tutorials on web technologies</description>
<link>http://www.melonfire.com/community/columns/trog/</link>
<items>
<rdf:seq>
<li
rdf:resource="http://www.melonfire.com/community/columns/trog/article.ph
p?id
=100" />
<li
rdf:resource="http://www.melonfire.com/community/columns/trog/article.ph
p?id
=71" />
<li
rdf:resource="http://www.melonfire.com/community/columns/trog/article.ph
p?id
=62" />
</rdf:seq>
</items>
</channel>
<item
rdf:about="http://www.melonfire.com/community/columns/trog/article.php?i
d=10
0">
<title>building a php-based mail client (part 1)</title>
<link>http://www.melonfire.com/community/columns/trog/article.php?id=100
</li
nk>
<description>ever wondered how web-based mail clients
work? find out here.</description>
</item>
<item
rdf:about="http://www.melonfire.com/community/columns/trog/article.php?i
d=71">
<title>using php with xml (part 1)</title>
<link>http://www.melonfire.com/community/columns/trog/article.php?id=71<
/link>
<description>use php''s sax parser to parse xml data and
generate html pages.</description>
</item>
<item
rdf:about="http://www.melonfire.com/community/columns/trog/article.php?i
d=62">
<title>access granted</title>
<link>http://www.melonfire.com/community/columns/trog/article.php?id=62<
/link>
<description>precisely control access to information
with the mysql grant tables.</description>
</item>
你可以看到,rdf文件由幾個界限分明的部分組成。首先是文檔序碼(prolog),
<?xml version="1.0" encoding="utf-8"?>
然后是根元素中的名稱空間聲明。
<rdf:rdf xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
xmlns="http://purl.org/rss/1.0/">
接著是<channel>部分,這部分包含了rdf所要描述的頻道的一般信息。在上面的例子中,頻道是melonfire網站的trog專欄,專欄內容是新的技術文章和指南,每星期更新一次。
<channel rdf:about="http://www.melonfire.com/">
<title>trog</title>
<description>well-written technical articles and
tutorials on web technologies</description>
<link>http://www.melonfire.com/community/columns/trog/</link>
<items>
<rdf:seq>
<li
rdf:resource="http://www.melonfire.com/community/columns/trog/article.ph
p?id
=100" />
<li
rdf:resource="http://www.melonfire.com/community/columns/trog/article.ph
p?id
=71" />
<li
rdf:resource="http://www.melonfire.com/community/columns/trog/article.ph
p?id
=62" />
</rdf:seq>
</items>
</channel>
<channel>區包含了一個<items>區塊,<items>區塊又包含了文檔中描述的所有資源的一個順序列表。該列表通過一系列的<li />元素來表示。區塊中每一個資源都在后面的<item>區塊中有更詳細的描述。
<items>
<rdf:seq>
<li
rdf:resource="http://www.melonfire.com/community/columns/trog/article.ph
p?id
=100" />
新聞熱點
疑難解答