顯示具有 rss 標籤的文章。 顯示所有文章
顯示具有 rss 標籤的文章。 顯示所有文章

[教學]給我Live Spaces訪客留言的RSS吧(用Feed43把網頁轉RSS)

此文首發於2007/07/11 20:27 於2008/10/10更新內容

首先,雖然不知道RSS融入了多少人的生活~不過我真的覺得RSS是我取得最新資訊的好工具~

話說身為RSS重度使用者的我,把生活與心情的東西用微軟的Live Spaces記錄。

姑且不論Live Spaces速度有點慢這個問題~也不論沒辦法用RSS訂閱最新的文章回應(因為上一篇有談到國良大大用Yahoo Pipes解決了這個問題)(Yahoo Pipes中可搜尋到有人有解決的pipe)~但是它新推出的訪客留言功能居然沒有提供RSS~這樣我怎麼知道有新留言呢~我可不想一直按那個重新整理的按鈕~

所以我就試了幾個免費的服務~最後找到了Feed43這個網站來把我的訪客留言變成RSS Feed~

PS. 最近頁面html有修改~我更新了一下語法~圖沒更新

怎麼做

首先到Feed43選擇【Create your own feed

輸入要轉為RSS Feed的網址,如我的留言板:http://al080.spaces.live.com/guestbook/

然後點選【Reload】

這時下面會出現網頁的原始碼給大家參考

再來的步驟為輸入轉換的規則,目前Live Spaces的訪客留言板規則如下,將下面這傳碼複製到【Item (repeatable) Search Pattern

<input type="hidden" id="sn_ccIdCommentControl{%}" value={*}<span dir='ltr'>{%}</span>{*}<div class="Comment" id="sn_ccHtmlCommentControl{*}">{%}</div>{_}</div>{_}<div class="ccDateBox{*}">{*}<span class="ccColor2">{%}</span>

輸入後點選【Extract】,下面就會出現分析的結果

接著到【RSS item properties】下輸入以下欄位內容:

Item Title Template:【{%4} (author: {%2})】

Item Link Template:【http://留言板網址/#sn_ccIdCommentControl{%1}】,如【http://al080.spaces.live.com/guestbook/#sn_ccIdCommentControl{%1}】

Item Content Template:

<div>{%3}</div>
<div>&nbsp;</div>
<div align="right">{%4}</div>

然後點選【Preview】,就可以看到產生的RSS Feed結果

最後你就可以看到Feed的網址,你可以點選【Change file name】讓Feed的網址比較容易記

並且要記得選【Change feed edit password】來設定這個Feed的修改密碼~

結語

雖然這樣就能擁有RSS Feed,不過這樣的做法是治標不治本~

首先因為Feed43產生的Feed沒有時間的欄位~而且如果哪天Live Spaces改掉訪客留言的版面~我們也要跟著修改轉換的規則~

所以還是請大家有需要的人多寫幾封建議信去給網站讓他們提供RSS吧~

相關文章

[ 心得]新一代網路重度使用者到底在玩什麼

大約是在當學生的最後一年中~我從一個對網際網路有點興趣的人~

變成了重度使用者~其中一部分原因是Web 2.0相關的服務變多的原因~

雖說身為資工的學生~這是再正常不過了~

不過說重度其實是個模糊的形容~

因為我身邊有一堆玩技術玩的比我兇的人~

不過當我意識過來時~

我才發現~身邊的人就算知道一堆東西的存在~

但真正會去用的卻不多~而我卻因此把用這些東西變成習慣~

搞的有點資訊躁鬱症~

有那麼嚴重嗎?~咱們來看看你陷入網路的世界有多深~

RSS

這算是我陷入的主要原因~

簡單說RSS是個資訊來源的協定~它需要一個訂閱的工具,可以訂閱你關注的網站~

當網站有更新的資訊他會把新文章的全文或摘要放在RSS,這時你的訂閱工具就可以去讀那份RSS~

告訴你網站更新囉~並且你可以利用訂閱工具直接閱讀這個文章~

讓你不用我的最愛在那點半天,還不知道那個網站更新過了沒~

這對於像是有一堆朋友有Blog~或是每天都有逛網站看有沒有新資訊的我來說~

真的是如虎添翼~

也因此養成我會隨手去點一下我的RSS訂閱器(SharpReader)的習慣~

喜歡Blog勝於手寫日記

手寫的實在太麻煩,要放圖不行,不能連到別的文章,不能與別人分享...

如果你是像我有這種感覺的人~

我想你應該會喜歡寫Blog~

不過我想重度使用者並不完全跟我一樣~

也有另一部份自己寫的不多~但喜歡看朋友或是別人的Blog~

也因此會需要上面的RSS

  • Blogger Google收購的Blog服務,可以客製的功能很多~卻也因此難入門
  • Spaces Live 微軟的Blog服務,因為跟Live Message結合而使我想用它
  • Yahoo!奇摩部落格 Yahoo的,基本上該有的功能也都有
  • 無名小站 說是台灣的奇蹟~近來卻因為行政問題鬧出許多問題
  • Yam天空 一直做的不差卻也沒有亮眼的台灣Blog服務~不過近來小動作頻頻~讓人期待
  • PIXNET 痞客邦 跟無名一樣從相簿開始
  • StreetVoice 許多藝術創作者聚集的Blog

搭配其他程式的網路服務

像是利用MSN、Google talk等軟體來公佈一些自己的事~

如Twritter、巴布、iSay...等

讓別人知道自己正在做什麼或想什麼事~

或是用MSN或Email訂閱RSS等服務~

我自己會用MSN來發巴布的訊息同步到Twritter,

還有用MSN配合MyIcon的iSay來收別人留給我的訊息~

逛書籤網站

我覺得書籤網站是互動性需要很高的服務~

雖然就我觀察在台灣真的會花很多時間在收藏書籤的人比例其實不算高~

不過這樣的網站可以讓我滿足想看看別人

挖到什麼好文章、有什麼新資訊、好笑的影片~

所以逛逛這樣的網站或訂他的RSS也可以挖到不少好東西~

  • HEMiDEMi 台灣打前鋒的書籤網站
  • funP 用不同概念在經營的書籤網站
  • MyShare 智邦的書籤網站
  • Search 2.0 Pchome新推出的書籤網站

用網站服務取代應用程式

自從Web 2.0與AJAX等東西的出現,

網路上出現許多好用的服務,

有許多服務甚至足以取代現有的本機應用程式~

因此幾乎都掛在網路上的人就開始能不安裝的程式就不安裝,

用網路上的服務取代~

像是Word、Excel、FontPage、Outlook、行事曆、地圖、字典的取代品

而其中又以Google推出或收購的服務目前佔了大部分~

喜歡嘗試新服務、有的沒的小玩意

當陷入到一個新資訊躁鬱的狀態後~

就會開始出現新的症狀,

就是覺得別人的資料已經不足以彌補躁鬱帶來的急躁感~

就會開始自己挖東西~也就會開始玩些有的沒的~

不知不覺用掉一堆時間~


例如一開始會在自己的Blog動手腳,

開始找些有的沒的小玩意放在自己的Blog~

像是小寵物、外掛等~

然後進一步看到別人介紹或是自己逛到的網路服務或是小工具~

就會想去試一試~

然後更進一步會思考自己能怎麼用這些服務~

甚至自己用一些方式來組合服務~

下面列出與一堆服務相關的教學與文章~

結語

我大致上列了一些我覺得Web 2.0時代重度使用者的特性~

並且把一些我覺得滿經典的網站相關文章連結列出來~

我自己覺得當個重度使用者的壞處就是花太多時間在網路上逛了~

至於當個重度使用者的特性是否只有這些~

那就如同Web 2.0一般~只會不斷進化~

但花在電腦前的時間就是重度使用者的指標~

如果你要說重度使用者是御宅族~我想這就看怎麼定義了~

維基百科中就有提到台灣的御宅族定義與日本已經不同了~

像我這樣花一堆時間在電腦與電視前的人就算沒到很嚴重的程度~

也算是危險群了~


我只能勸勸跟我一樣危險的人~

如果可以~好好規劃自己再電腦前與起來動一動的時間平均一點~

有空多往外面走吧~多接觸實際的人吧~

RSS合併效果比較(RSSMixer與Yahoo Pipes)

最近看到了一篇Werboy寫的究極RSS合體術!不管你有多少個RSS,全部幫你合而為一 - RSSMixer

介紹到一個新的RSS合併網站-RSSMixer,專門讓大家能把自己很多個RSS併成一個RSS~

其實這個功能我在管你有幾個Blog,就是要你的最新資訊(Yahoo Pipes+FeedBurner)這篇就有用Yahoo Pipes達成過~

這樣的功能能讓有多個Blog、有Twritter、或是其它服務而有很多個RSS的人~

可以將RSS合併~讓使用者可以一次訂閱你的最新資訊~

當然如同Werboy談到的~也可以把一堆人的RSS或是一堆網站的RSS合併起來方便訂閱~

但我玩了一下RSSMixer後(玩的結果),發現了一些細節上的結果差異~

既然已經有人寫了使用教學~那我也不重複了~

以下就來談談這兩者的差異吧

Yahoo Pipes與RSSMixer的差異

其實這兩者因為方向的不同,所以如果拿製作方式的差異來比可能不是那麼公平~

不過就把RSS合併這方面來看呢~

  • 製作方式的差異
    因為RSSMixer玩全專注在合併這方面,所以使用者就輸入要合併的RSS網址就好了,沒有多餘的東西~
    而Pipes除了合併外,還要加上以日期排序等元件~製作起來步驟比較多~
    而且RSSMixer不用登入就可製作
  • 管理差異
    雖然RSSMixer不用登入就可製作,可以讓使用的時候少掉註冊等事~
    不過確也犧牲掉讓使用者能管理維護自己的RSS功能~所以以後如果要修改就要重建一個RSS了~
    但Pipes原本就可能讓大家修修改改~所以沒這個問題~
  • 網址差異
    Pipes所輸出的結果網址很複雜~
    而RSSMixer則用妳輸入的名稱的英文與數字來產生一個簡短的網址~但如果是全中文名稱則會出現一個亂數的數字的樣子當網址~
  • 篇數差異
    如果按照我的教學用Pipes來合併RSS,基本上如果每個RSS有20篇文章,3個RSS合併後的RSS就會有60篇文章~
    當然~因為Pipes可以客製化的能力比較多,用Operator的【Truncate】元件就可以指定最後輸出的篇數限制~
    而RSSMixer則預設就是25篇了~
  • 內容差異
    基本上Pipes會直接把你的RSS內容輸出~但RSSMixer就我的觀察它好像隱藏掉HTML的內容~
    例如下面這張圖,同樣一篇原本有圖的文章,經過RSSMixer後就沒有圖了,換行也消失~
  • 結果呈現差異
    Pipes在解果呈現時,讓大家可以選用RSS訂閱、My Yahoo、Google、Bloglines...等~
    而RSSMixer另外提供了Apple Dashboard Widget、Web Widget、iPhone等方式來訂閱
    其中的Web Widget是讓你可以用Html與Script放在網站邊邊來呈現結果的功能~不過我覺得這只是加一點語法來呈現RSS~

總結

就複雜度來說,RSSMixer當然是簡單許多~

但為了以後還能修改RSS的來源,我還是會用Yahoo Pipes~

不過現在的RSSMixer還只是Prototype v0.1~

很難說現在的功能就會是以後的功能~

如果只是想很快的合併RSS的話~不妨去玩玩看RSSMixer~

你會發現原來RSS一點也不難用~

管你有幾個Blog,就是要你的最新資訊(Yahoo Pipes+FeedBurner)

話說閉關了一陣子,很久沒記錄些新的東西了~

今天跟大家又要跟大家談談RSS了~

其實在網路上逛的人,我想可能有10%有用RSS的習慣就很了不起了,我是覺得好像真的不多人用。

但我個人算是RSS的愛用者,甚至到了沒有RSS會很難過的地步~

為此,我發現了一個有趣的玩法~

不知道大家會不會有個需求~就是像我有兩個Blog,還有使用Twitter...

這些地方都有提供RSS,但是都是分開在各地~

如果我希望觀注我的人能夠一次訂到這些RSS的內容,甚至未來我有新的資訊來源的RSS,訂閱我的人都能在一次訂閱後就能不再需要擔心這些問題~

那麼我該如何做呢~

使用服務

其實我一說出下面兩個服務,明眼人就知道我要做什麼了~

  • Yahoo Pipes:以Web圖形化介面提供邊輯工具,進行RSS的處理、過濾、重組、排序等功能
  • FeedBurner:以自定的網址,提供使用者永久的RSS網址,讓使用者可以訂閱後就不用擔心網站搬家使RSS位址改變的問題,管理者還可得到更多的統計資訊

怎麼做

話說我的資訊來源為

為了要讓使用者可以很容易訂閱,所以我將這些RSS利用Yahoo Pipes組合,過程如下:

先到Yahoo Pipes以Yahoo帳號登入後,點選【Create a pipe】

此時會開啟Yahoo pipes的編輯畫面,在這畫面中可以拖拉的方式設計資料處理邏輯

我們需要的是取得RSS Feed的處理,因此從左邊的Source找到【Fetch Feed】,加到編輯區中

將我需要合併的RSS網址都加到這個元件中

為了讓他產生時能先排序,從Operations找到【Sort】元件,加到編輯區

先將畫面中的三個元件連起來,讓Sort知道他有什麼東西可排序

選擇排序條件:item.pubDate、descending,已發佈時間越新的越上面

然後到右上角選儲存【Save】

第一次儲存他會問要取什麼名字,輸入後選擇【Save】

儲存後,上方會出現【Run Pipe...】,點選他看看結果

這時所出現的就是你的結果,也就是RSS的合併結果。我需要他的RSS,所以點選【Subscribe】→【Get as RSS】。然後複製起來RSS網址,例如我的是【http://pipes.yahoo.com/pipes/pipe.run?_id=LOoSs2Yl3BG9cK_Rl7okhQ&_render=rss】

為了讓使用者好訂閱,未來也不用擔心如果網址變更,還要通知使用者變更。我們到FeedBurner,註冊一個帳號,然後要把剛才的RSS燒成一個新的RSS網址。

將RSS網址貼上後,選擇【Next】

然後輸入名稱與新的RSS網址,選擇【Activate Feed】

成功後就會出現下面的畫面,如果不成功有可能是你選的新RSS網址已有人使用。

如此一來,我就擁有一個把我所有網站新資訊合併後的新RSS【http://feeds.feedburner.com/al080

延伸應用

當然,既然可以合併RSS,我們就很做很多類似的應用。

例如說,我的兩個Blog,Blogger原本就提供了訂閱最新回應的RSS,而Spaces Live雖然留言的部份是單篇單篇訂閱的,不過搜尋一下,就會發現有位國良大大做的Pipes,可以將你的Spaces Live最新20篇文章的回應RSS抓出來。

用法很簡單,到【http://pipes.yahoo.com/pipes/pipe.info?_id=lJZ2nboZ3BGBoB2pJZhxuA】,會出現要你輸入帳號的地方,像我的Spaces網址是al080開頭,就以此輸入。

然後就跟剛才一樣,可以得到對應的RSS,重複剛才的動作就可以再把Blogger的回應也組合起來,便成了我自己在看有沒有新回應的RSS Feed了唷。

最後的結果就如同我最後產生的這個回應的RSS:http://feeds.feedburner.com/alcomment080

結論

Yahoo Pipes可做的事應該很多,只是我還不太熟悉這樣的開發環境。不過有個好的開始就是不錯的事,大家有興趣可以玩玩看別的方式~像國良大大能將完成那樣就應該很熟了吧~

說真的~RSS的使用到底有多普遍~我真的不知道~

可以發現的是~大多數網站都漸漸的有提供RSS~

可是又會有些例外~像是有些人Blog設為只有朋友才能看~可是這樣卻又不能訂閱他的RSS~這樣子我會逛到他的網站的頻率真的會降很多~

可是有的Blog內容就是希望只有特定人看到~

我覺得這到目前都還很少Blog去解決這件問題~(畢竟RSS用戶是小眾???)

無論如何~我希望未來RSS還會比現在方便~像是回應更方便等~

但我想會出現那樣的事~前提就是使用者更多吧~

換回SharpReader

前陣子寫了一篇比較7個RSS Reader與GreateNews使用教學之後,

我用了GreatNews一個月,

發現它有個嚴重的bug,

就是會掉文章~

也就是明明有的網站有新的文章,

GreatNews確沒顯示出來~

雖然不是每個網站都如此,

但有幾個我常看的網站會這樣~

所以最近我忍不住,又換回SharpReader~

順道一提~

我那時換RSS Reader之一的原因,是SharpReader的官網也掛了~

不過最近開又好了~

可是作者還是沒有新的版本釋放出來...

用VB.Net寫的RSS Feed產生函式

我自己是很喜歡用RSS的服務的人,所以寫網站或是做一些事時常會想到要弄個RSS Feed,最起碼自己會用的到~

不過VB中並沒有直接提供RSS Feed的產生函式,國外有些網站好像有提供類似的東西,不過不是要註冊就是有些複雜,所以我就自己寫了一個~

作法

我原本是用FileIO那篇的寫文字檔的方式,用比較笨的方法產生RSS Feed~

不過後來我改用以下的內容,將RSS的內容,以Xml.XmlDocument這個類別來產生XML的結構,順便學習在VB.Net下怎麼自己產生XML結構,並且它會自己將HTML編碼的問題解決

RSS 2.0的規格則是參考RSS 2.0 Specification中的規定,來設計RSS feed的元素,不過我剔除掉了一些我覺得沒用或是我看不出來功能的標籤,來產生結果

模組程式碼

Imports System
Module RSSGenModule
   ''' 
   ''' RSSGenerator V1.0 is builded by Allen
   ''' Please get the newest information at
   ''' http://allen080.blogspot.com/
   ''' 
   Public Class RSSGenerator
       Public Sub createRSS(ByRef rssfeed As RSSFeed, ByVal path As String)
           'RSS 2.0 specification is Reference at
           'http://www.rssboard.org/rss-specification/
           Dim x As New Xml.XmlDocument
           x.LoadXml("" + "" + "")

           Dim channel As Xml.XmlElement = x.CreateElement("channel")
           x.DocumentElement.AppendChild(channel)

           Dim element As Xml.XmlElement
           Dim subElement As Xml.XmlElement
           'set channel start
           element = x.CreateElement("title")
           channel.AppendChild(element)
           element.InnerText = rssfeed.title
           If Not rssfeed.link Is Nothing Then
               element = x.CreateElement("link")
               channel.AppendChild(element)
               element.InnerText = rssfeed.link
           End If
           If Not rssfeed.description Is Nothing Then
               element = x.CreateElement("description")
               channel.AppendChild(element)
               element.InnerText = rssfeed.description
           End If
           If Not rssfeed.language Is Nothing Then
               element = x.CreateElement("language")
               channel.AppendChild(element)
               element.InnerText = rssfeed.language
           End If
           If Not rssfeed.copyright Is Nothing Then
               element = x.CreateElement("copyright")
               channel.AppendChild(element)
               element.InnerText = rssfeed.copyright
           End If
           If Not rssfeed.managingEditor Is Nothing Then
               element = x.CreateElement("managingEditor")
               channel.AppendChild(element)
               element.InnerText = rssfeed.managingEditor
           End If

           If Not rssfeed.webMaster Is Nothing Then
               element = x.CreateElement("webMaster")
               channel.AppendChild(element)
               element.InnerText = rssfeed.webMaster
           End If

           element = x.CreateElement("pubDate")
           channel.AppendChild(element)
           element.InnerText = (rssfeed.pubDate.AddHours(-8)).ToString("r")

           element = x.CreateElement("lastBuildDate")
           channel.AppendChild(element)
           element.InnerText = (rssfeed.lastBuildDate.AddHours(-8)).ToString("r")

           If Not rssfeed.category Is Nothing Then
               element = x.CreateElement("category")
               channel.AppendChild(element)
               element.InnerText = rssfeed.category
           End If
           If Not rssfeed.generator Is Nothing Then
               element = x.CreateElement("generator")
               channel.AppendChild(element)
               element.InnerText = rssfeed.generator
           End If
           If Not rssfeed.docs Is Nothing Then
               element = x.CreateElement("docs")
               channel.AppendChild(element)
               element.InnerText = rssfeed.docs
           End If


           If Not rssfeed.image Is Nothing Then
               element = x.CreateElement("image")
               channel.AppendChild(element)
               'set image start
               If Not rssfeed.image.title Is Nothing Then
                   subElement = x.CreateElement("title")
                   element.AppendChild(subElement)
                   subElement.InnerText = rssfeed.image.title
               End If
               If Not rssfeed.image.link Is Nothing Then
                   subElement = x.CreateElement("link")
                   element.AppendChild(subElement)
                   subElement.InnerText = rssfeed.image.link
               End If
               subElement = x.CreateElement("url")
               element.AppendChild(subElement)
               subElement.InnerText = rssfeed.image.url
               If Not rssfeed.image.description Is Nothing Then
                   subElement = x.CreateElement("description")
                   element.AppendChild(subElement)
                   subElement.InnerText = rssfeed.image.description
               End If
               'set image end
           End If
           If Not rssfeed.itmes Is Nothing Then
               For Each item As RSSElement In rssfeed.itmes
                   element = x.CreateElement("item")
                   channel.AppendChild(element)
                   'set item start
                   subElement = x.CreateElement("title")
                   element.AppendChild(subElement)
                   subElement.InnerText = item.title
                   If Not item.link Is Nothing Then
                       subElement = x.CreateElement("link")
                       element.AppendChild(subElement)
                       subElement.InnerText = item.link
                   End If
                   If Not item.description Is Nothing Then
                       subElement = x.CreateElement("description")
                       element.AppendChild(subElement)
                       subElement.InnerText = item.description
                   End If
                   If Not item.author Is Nothing Then
                       subElement = x.CreateElement("author")
                       element.AppendChild(subElement)
                       subElement.InnerText = item.author
                   End If
                   If Not item.category Is Nothing Then
                       subElement = x.CreateElement("category")
                       element.AppendChild(subElement)
                       subElement.InnerText = item.category
                   End If
                   If Not item.comments Is Nothing Then
                       subElement = x.CreateElement("comments")
                       element.AppendChild(subElement)
                       subElement.InnerText = item.comments
                   End If
                   If Not item.guid Is Nothing Then
                       subElement = x.CreateElement("guid")
                       subElement.SetAttribute("isPermaLink", "false")
                       element.AppendChild(subElement)
                       subElement.InnerText = item.guid
                   End If

                   subElement = x.CreateElement("pubDate")
                   element.AppendChild(subElement)
                   subElement.InnerText = (item.pubDate.AddHours(-8)).ToString("r")
                   'set item end
               Next
           End If
           'set channel end

           'write to file
           Dim settings As New Xml.XmlWriterSettings()
           settings.Indent = True
           settings.IndentChars = "    "
           settings.Encoding = System.Text.Encoding.UTF8
           Using writer As Xml.XmlWriter = Xml.XmlWriter.Create(path, settings)
               x.WriteTo(writer)
               writer.Flush()
           End Using
       End Sub
   End Class

   Public Class RSSElement
       Private _title As String
       Private _link As String
       Private _description As String
       Private _author As String
       Private _category As String
       Private _comments As String
       Private _guid As String
       Private _pubDate As Date
       Public Property pubDate() As Date
           Get
               Return _pubDate
           End Get
           Set(ByVal value As Date)
               _pubDate = value
           End Set
       End Property

       Public Property guid() As String
           Get
               Return _guid
           End Get
           Set(ByVal value As String)
               _guid = value
           End Set
       End Property

       ''' 
       ''' 回應的URL
       ''' 
       Public Property comments() As String
           Get
               Return _comments
           End Get
           Set(ByVal value As String)
               _comments = value
           End Set
       End Property
       Public Property category() As String
           Get
               Return _category
           End Get
           Set(ByVal value As String)
               _category = value
           End Set
       End Property

       ''' 
       ''' E-Mail
       ''' 
       Public Property author() As String
           Get
               Return _author
           End Get
           Set(ByVal value As String)
               _author = value
           End Set
       End Property

       Public Property description() As String
           Get
               Return _description
           End Get
           Set(ByVal value As String)
               _description = value
           End Set
       End Property

       Public Property title() As String
           Get
               Return _title
           End Get
           Set(ByVal value As String)
               _title = value
           End Set
       End Property
       Public Property link() As String
           Get
               Return _link
           End Get
           Set(ByVal value As String)
               _link = value
           End Set
       End Property
   End Class

   Public Class RSSImage
       Private _title As String
       Private _link As String
       Private _url As String
       Private _description As String
       Public Property description() As String
           Get
               Return _description
           End Get
           Set(ByVal value As String)
               _description = value
           End Set
       End Property

       Public Property url() As String
           Get
               Return _url
           End Get
           Set(ByVal value As String)
               _url = value
           End Set
       End Property

       Public Property link() As String
           Get
               Return _link
           End Get
           Set(ByVal value As String)
               _link = value
           End Set
       End Property

       Public Property title() As String
           Get
               Return _title
           End Get
           Set(ByVal value As String)
               _title = value
           End Set
       End Property
   End Class

   Public Class RSSFeed
       Private _title As String
       Private _link As String
       Private _description As String
       Private _language As String = "zh-tw"
       Private _copyright As String
       Private _managingEditor As String
       Private _webMaster As String
       Private _guid As String
       Private _pubDate As Date = Now
       Private _lastBuildDate As Date = Now
       Private _category As String
       Private _generator As String
       Private _docs As String = "http://www.rssboard.org/rss-specification"
       Private _image As RSSImage
       Private _items As ArrayList

       ''' 
       ''' 元素型態是RSSElement
       ''' 
       Public Property itmes() As ArrayList
           Get
               Return _items
           End Get
           Set(ByVal value As ArrayList)
               _items = value
           End Set
       End Property
       Public Property image() As RSSImage
           Get
               Return _image
           End Get
           Set(ByVal value As RSSImage)
               _image = value
           End Set
       End Property

       ''' 
       ''' URL
       ''' 
       Public Property docs() As String
           Get
               Return _docs
           End Get
           Set(ByVal value As String)
               _docs = value
           End Set
       End Property

       Public Property generator() As String
           Get
               Return _generator
           End Get
           Set(ByVal value As String)
               _generator = value
           End Set
       End Property

       Public Property category() As String
           Get
               Return _category
           End Get
           Set(ByVal value As String)
               _category = value
           End Set
       End Property

       Public Property lastBuildDate() As Date
           Get
               Return _lastBuildDate
           End Get
           Set(ByVal value As Date)
               _lastBuildDate = value
           End Set
       End Property
       Public Property pubDate() As Date
           Get
               Return _pubDate
           End Get
           Set(ByVal value As Date)
               _pubDate = value
           End Set
       End Property

       Public Property guid() As String
           Get
               Return _guid
           End Get
           Set(ByVal value As String)
               _guid = value
           End Set
       End Property

       ''' 
       ''' E-Mail
       ''' 
       Public Property managingEditor() As String
           Get
               Return _managingEditor
           End Get
           Set(ByVal value As String)
               _managingEditor = value
           End Set
       End Property

       ''' 
       ''' E-Mail
       ''' 
       Public Property webMaster() As String
           Get
               Return _webMaster
           End Get
           Set(ByVal value As String)
               _webMaster = value
           End Set
       End Property

       Public Property copyright() As String
           Get
               Return _copyright
           End Get
           Set(ByVal value As String)
               _copyright = value
           End Set
       End Property

       Public Property language() As String
           Get
               Return _language
           End Get
           Set(ByVal value As String)
               _language = value
           End Set
       End Property

       Public Property description() As String
           Get
               Return _description
           End Get
           Set(ByVal value As String)
               _description = value
           End Set
       End Property

       Public Property title() As String
           Get
               Return _title
           End Get
           Set(ByVal value As String)
               _title = value
           End Set
       End Property
       Public Property link() As String
           Get
               Return _link
           End Get
           Set(ByVal value As String)
               _link = value
           End Set
       End Property
   End Class

End Module

使用方法

這個模組中主要有4個類別,分別是

  • RSSFeed:整個RSS的資料都存在這裡面,如果沒有被設定到的屬性,就不會被寫入檔案中(日期除外)
  • RSSImage:用來顯示Logo的資訊,如果沒有Logo就不要把它設定給RSSFeed就好了
  • RSSElement:用來存每一筆新資訊的地方,在RSSFeed中是被ArrayList存起來的
  • RSSGenerator:將路徑與RSSFeed交給其中的createRSS函式,就能產生一個RSS feed檔

使用範例

            Dim rssfeed As New RSSFeed
           rssfeed.title = title
           rssfeed.link = url
           rssfeed.description = title
           rssfeed.generator = "倫倫3號"
           rssfeed.webMaster = "allen080+Tech@gmail.com"
           Dim rssimage As New RSSImage
           rssfeed.image = rssimage
           rssimage.title = title
           rssimage.link = url
           rssimage.url = url + "images/fslogo.jpg"
           rssfeed.itmes = New ArrayList
           Dim notes As ArrayList = gbdatas
           For Each item As GuestBookData In notes
               Dim rsselement As New RSSElement
               rsselement.title = item.title
               rsselement.author = item.eMail + " (" + item.name + ")"
               rsselement.link = item.url
               rsselement.description = item.content
               rsselement.pubDate = item.time
               rsselement.guid = item.url
               rssfeed.itmes.Add(rsselement)
           Next

           Dim rssgen As New RSSGenerator
           rssgen.createRSS(rssfeed, path)

總結

有這樣的一個類別就可以很快的產生出屬於自己的RSS Feed,當然這個xml檔要放在網頁伺服器上,我通常是用IIS就解決了~

完成的檔案可以透過Feed Validator for Atom and RSS這樣的網站來做驗證,不過如果只是一些小警告、小錯誤不理他也沒關係,只要你的RSS Reader不會讀不出來就好了

寫完這個RSS產生函式,如果有空我會找時間看看Atom的不同,如果有必要,也會寫Atom的版本~

參考連結

這裡是關於技術的手札~

也歡迎大家到

倫與貓的足跡



到噗浪來

關心一下我唷!
by 倫
 
Copyright 2009 倫倫3號Beta-Log All rights reserved.
Blogger Templates created by Deluxe Templates
Wordpress Theme by EZwpthemes