XQuery/Simple RSS reader

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

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

News Page[edit]

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
 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>

Execute

Text-to-Speech[edit]

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.

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>

Execute

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]

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


UWE news Execute