跳轉到內容

XQuery/簡單 RSS 閱讀器

來自華夏公益教科書,開放書籍,開放世界

BBC 提供了各種 RSS 新聞源,例如 英國教育新聞

新聞頁面

[編輯 | 編輯原始碼]

將 RSS 提要重新格式化為 HTML

declare option exist:serialize "method=xhtml media-type=text/html";

let $news := doc("http://newsrss.bbc.co.uk/rss/newsonline_uk_edition/education/rss.xml")
 let $dateTime := $news/rss/channel/lastBuildDate
 return 
<html>
   <body>
       <h2>Education news from the BBC at {string($dateTime)}</h2>
         { for $newsItem in $news/rss/channel/item[position() < 10]
           return 
           <div>
               <h4>{string($newsItem/title)}</h4>
               <p>{string($newsItem/title/description)} <a href="{$newsItem/link}">more..</a></p>
          </div>
       }
    </body>
</html>

執行

文字轉語音

[編輯 | 編輯原始碼]

帶語音擴充套件的 Opera 瀏覽器支援文字轉語音,允許將此新聞朗讀出來。 這使用 XML 詞彙 VoiceXMLXML 事件。 [2019-01-26 : 遺憾的是,Opera 不再支援 VoiceXML]

declare option exist:serialize  "method=xhtml media-type=application/xv+xml";

let $news := doc("http://newsrss.bbc.co.uk/rss/newsonline_uk_edition/education/rss.xml")
let $dateTime := $news/rss/channel/lastBuildDate
let $newsItems :=  $news/rss/channel/item[position() < 10]
return 
<h:html xmlns:h="http://www.w3.org/1999/xhtml" 
      xmlns:vxml="http://www.w3.org/2001/vxml" 
      xmlns:ev="http://www.w3.org/2001/xml-events" 
>
   <h:head>
      <h:title>BBC Education news</h:title>
      <vxml:form id="news">
          <vxml:block>
              {for $newsItem in $newsItems
               return    string($newsItem/description)
              }
         </vxml:block>
      </vxml:form>
    </h:head>
    <h:body>
       <h:h1>BBC Education news  at {string($dateTime)}</h:h1>
       <h:p>
          <h:a ev:event="click" ev:handler="#news" >
             <h:img src="http://www.naturalreaders.com/images/laba.gif"/>
          </h:a>  
               (Requires the Opera Browser with Voice extension)
       </h:p>
       { for $newsItem in  $newsItems
         return 
           <h:div>
              <h:h4>{string($newsItem/title)}</h:h4>
              <h:p>{string($newsItem/description)} <h:a href="{$newsItem/link}">more..</h:a></h:p>
           </h:div>
       }
    </h:body>      
</h:html>

執行

請注意,html 名稱空間已指定字首,以便預設字首可以引用 RSS 提要。

通用 RSS 閱讀器

[編輯 | 編輯原始碼]

更一般地說,可以朗讀任何 RSS 提要的閱讀器將是一項有用的服務。


UWE 新聞 執行

華夏公益教科書