名譽和巨大的財富
設想一個從最熱門的門戶網站獲得最新的新聞的站點。股票價格,天氣信息,新聞故事,線式討論組,軟件發布……所有這一切都將被動態更新,每小時一次,不需要任何手工干預。我們可以想象這隨之而來的站點訪問量,源源不斷的廣告收入以及網管大人所受到的“阿諛奉承”。
但是現在,停止幻想,開始閱讀,因為只要你密切關注此項技術,說不定你就能成為站點的主人。 對你的要求也只是稍許的想象力,一些聰明的PHP編碼和幾個免費的RSS文件。另外,很明顯還包括這篇文章剩下的九個部分。
有內容,就聯合成辛迪加(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文檔可以被其它站點獲取(如站點B,“內容收集者”),分析并顯示在站點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文件。
交換頻道(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/">
/t <title>Trog</title>
/t <description>Well-written technical articles and
tutorials on Web technologies</description>
<link>http://www.melonfire.com/community/columns/trog/</link>
/t <items>
/t/t <rdf:Seq>
/t/t/t <li
rdf:resource="http://www.melonfire.com/community/columns/trog/article.ph
p?id
=100" />
/t/t/t <li
rdf:resource="http://www.melonfire.com/community/columns/trog/article.ph
p?id
=71" />
/t/t/t <li
rdf:resource="http://www.melonfire.com/community/columns/trog/article.ph
p?id
=62" />
/t/t </rdf:Seq>
/t </items>
</channel>
<item
rdf:about="http://www.melonfire.com/community/columns/trog/article.php?i
d=10
0">
/t <title>Building A PHP-Based Mail Client (part 1)</title>
<link>http://www.melonfire.com/community/columns/trog/article.php?id=100
</li
nk>
/t <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">
/t <title>Using PHP With XML (part 1)</title>
<link>http://www.melonfire.com/community/columns/trog/article.php?id=71<
/link>
/t <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">
/t <title>Access Granted</title>
<link>http://www.melonfire.com/community/columns/trog/article.php?id=62<
/link>
/t <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/">
/t <title>Trog</title>
/t <description>Well-written technical articles and
tutorials on Web technologies</description>
<link>http://www.melonfire.com/community/columns/trog/</link>
/t <items>
/t/t <rdf:Seq>
/t/t/t <li
rdf:resource="http://www.melonfire.com/community/columns/trog/article.ph
p?id
=100" />
/t/t/t <li
rdf:resource="http://www.melonfire.com/community/columns/trog/article.ph
p?id
=71" />
/t/t/t <li
rdf:resource="http://www.melonfire.com/community/columns/trog/article.ph
p?id
=62" />
/t/t </rdf:Seq>
/t </items>
</channel>
<channel>區包含了一個<items>區塊,<items>區塊又包含了文檔中描述的所有資源的一個順序列表。該列表通過一系列的<li />元素來表示。區塊中每一個資源都在后面的<item>區塊中有更詳細的描述。
<items>
/t/t <rdf:Seq>
/t/t/t <li
rdf:resource="http://www.melonfire.com/community/columns/trog/article.ph
p?id
=100" />
/t/t/t <li
rdf:resource="http://www.melonfire.com/community/columns/trog/article.ph
p?id
=71" />
/t/t/t <li
rdf:resource="http://www.melonfire.com/community/columns/trog/article.ph
p?id
=62" />
/t/t </rdf:Seq>
/t </items>
還可以在其中放置一個<image>區塊,這樣你就可以發布頻道標志的URL。
所以為了肉,RSS1.0文檔中的每一個<item>區塊都更詳細地描述一個單獨的資源,包括標題,URL和資源描述。
<items>
/t/t <rdf:Seq>
/t/t/t <li
rdf:resource="http://www.melonfire.com/community/columns/trog/article.ph
p?id
=100" />
/t/t/t <li
rdf:resource="http://www.melonfire.com/community/columns/trog/article.ph
p?id
=71" />
/t/t/t <li
rdf:resource="http://www.melonfire.com/community/columns/trog/article.ph
p?id
=62" />
/t/t </rdf:Seq>
/t </items>
在這個例子里,<item>區塊描述了Ttrog“頻道”中單獨的一篇文章,并為這篇文章提供了描述和標題,以及URL。內容收集者可以利用URL創建“向后”鏈接。
你看得到,RSS1.0文件相當地直觀明了,不管是手工,還是通過編程,都非常容易創建。上面的例子和解釋僅僅是說明性質的,通常,你可以用RSS1.0和RDF做更多的事情。你最好看一下文章末尾提供的鏈接,以獲取更多的信息。不過在這之前,我們再花幾分鐘討論一如何將RSS1.0文檔插入到你自己的Web站點之中。
新聞熱點
疑難解答
圖片精選