XQuery/Simple RSS reader

From Wikibooks, open books for an open world
Jump to navigation Jump to search

The BBC provides a wide range of RSS news feed, e.g. UK Educational news

News Page[edit | edit source]

Reformat the RSS feed as 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
       <h2>Education news from the BBC at {string($dateTime)}</h2>
         { for $newsItem in $news/rss/channel/item[position() < 10]
               <p>{string($newsItem/title/description)} <a href="{$newsItem/link}">more..</a></p>


Text-to-Speech[edit | edit source]

The Opera browser with Voice extension supports text-to-speech, allowing this news to be spoken. This uses the XML vocabularies VoiceXML and XML Events. [2019-01-26 : Sadly Opera no longer supports 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]
<h:html xmlns:h="http://www.w3.org/1999/xhtml" 
      <h:title>BBC Education news</h:title>
      <vxml:form id="news">
              {for $newsItem in $newsItems
               return    string($newsItem/description)
       <h:h1>BBC Education news  at {string($dateTime)}</h:h1>
          <h:a ev:event="click" ev:handler="#news" >
             <h:img src="http://www.naturalreaders.com/images/laba.gif"/>
               (Requires the Opera Browser with Voice extension)
       { for $newsItem in  $newsItems
              <h:p>{string($newsItem/description)} <h:a href="{$newsItem/link}">more..</h:a></h:p>


Note that the html namespace has been given a prefix, so that the default prefix can refer to the RSS feed.

Generic RSS reader[edit | edit source]

More generally, a reader which could voice any RSS feed would be a useful service.

UWE news Execute