Version 10 of TclHttpd RSS Processing

Updated 2004-08-26 10:48:17

WJR - There was a discussion on the TclHttpd mailing list about processing RSS. Here's a variant I came up with using tDOM and The Tcler's Wiki RSS feed (it should work with any RSS feed):

 [Doc_Dynamic]

 [
 package require http
 package require tdom

 html::set token [http::geturl http://mini.net/tcl/rss.xml]
 html::set rss_xml [http::data $token]

 html::set doc [dom parse $rss_xml]
 html::set root [$doc documentElement]
 html::set stories [$root selectNodes /rss/channel/item]
 ]

 [html::head {RSS Example}]

 <style type="text/css">
     body {
         font-family: Arial, Helvetica, sans-serif;
         font-size: 80%;
     }
     h1 {
         background: #f7f7f7;
         padding: 4px;
     }
     dt {
         font-size: 120%;
         font-weight: bold;
     }
     dd {
         margin: 10px;
     }
     #date {
         color: #999999;
     }
 </style>

 [html::bodyTag]

 [html::h1 {RSS Example}]

 <dl>
     [html::foreach story $stories {
         <dt>
             <a href="[[$story selectNodes link/text()] nodeValue]">
                 [[$story selectNodes title/text()] nodeValue]
             </a>
             <span class="date">
                 ([[$story selectNodes pubDate/text()] nodeValue])
             </span>
         </dt>
         <dd>[[$story selectNodes description/text()] nodeValue]</dd>
     }]
 </dl>

 [html::end]

tDOM and TclHttpd makes this pretty simple!


DG -- That little starter script got me going. I was messing with TclXML at first, but tDOM is a whole lot easier to use. See it in action [L1 ]


Category TclHttpd