Version 8 of A little RSS browser

Updated 2008-06-26 15:18:23 by LV

Michael Jacobson (16/06/2004) ~ Using RS's A little XML browser and adding some (very little) code here is a RSS tree browser.

http://mywebpages.comcast.net/jakeforce/RssBrowser.jpg


 # A little RSS Browser
 #  based on Richard Suchenwirth's XML Browser
 package require http
 package require BWidget
 package require tdom

 proc recurseInsert {w node parent} {
    set name [$node nodeName]
    if {$name=="#text" || $name=="cdata"} {
        set text [$node nodeValue]
        set fill black
        set icon file
    } else {
        set text <$name
        foreach att [$node attributes] {
            catch {append text " $att=\"[$node getAttribute $att]\""}
        }
        append text >
        set fill blue
        set icon folder
    }
    $w insert end $parent $node -text $text -fill $fill -image [Bitmap::get $icon] -helptext $::name
    foreach child [$node childNodes] {recurseInsert $w $child $node}
 }

 Tree .t -yscrollcommand ".y set"
 scrollbar .y -ori vert -command ".t yview"
 pack .y  -side right -fill y
 pack .t -side right -fill both -expand 1

 #package require autoproxy  ;# add if needed for proxy support
 #autoproxy::init            
 proc fetch {url} {
    set res [http::data [set tok [http::geturl $url]]]
    http::cleanup $tok
    return $res
 }

 # add more if desired
 set site {http://wiki.tcl.tk/rss.xml
           http://slashdot.org/slashdot.rss
           http://rss.news.yahoo.com/rss/topstories}

 foreach name $site {
        set xml [fetch $name]
        dom parse  $xml doc
        $doc documentElement root
        recurseInsert .t $root root
 }

MHo 2008-06-26: A Syntax error in startup script... appears. ActiveTcl 8.4.18 on w2k.

LV I made a URL change for the wiki's rss feed, put it into a file, and ran it against sparc solaris activetcl 8.5.2 and get:

$ /tmp/rss.tk    
error "syntax error" at line 1 character 49
"F//DTD HTML 2.0//EN"> <--Error-- 
<HTML><HEAD>
<TITLE>301 Moved Permanen"
    while executing
"dom parse  $xml doc"
    ("foreach" body line 3)
    invoked from within
"foreach name $site {
        set xml [fetch $name]
        dom parse  $xml doc
        $doc documentElement root
        recurseInsert .t $root root
 }"
    (file "/tmp/rss.tk" line 46)