RSS == Description == This tutorial shows how the various HOP facilities for downloading and parsing XML documents can be used to implement RSS readers. This tutorial builds a function ++rss->html++ that accepts the URL of a RSS feeds and build a HOP tree for representing it. It rests on the server function ++with-url++ to manage the connection with the remote host and on the function ++feed-parse++ to build the tree. == Utility functions == The ++feed-parse++ function excepts to be invoked with tree constructors for building its representation of the RSS feeds. We start by providing implementation for these constructors. In this simple version, we implement them as simple ,( "HTML" "html.wiki") elements: (module rh-utils (export make-rss make-channel make-item)) (define (make-rss channel items) (
:style "border: 1px solid black; background: #ddd" channel (map (lambda (i) (
i)) items))) (define (make-channel #!key link title) ( ( ( :href link title)))) (define (alternate links) (when (pair? links) (let ((e (assq 'alternate links))) (when (pair? e) (let ((c (assq 'href (cdr e)))) (when (pair? c) (cdr c))))))) (define (make-item #!key links title date categories summary) (
:style "border: 1px solid #ccc; margin: 1px; padding: 2px;" ( :href (alternate links) title) (if date (list "(" date ")") "") (if categories ( categories)) summary)) == ++rss->html++ v1 == The function ++rss->html++ simply opens a connection and parses the read character. A simple implementation can be: (module rh-v1 (import rh-utils)) (define (rss->html-v1 url) (with-url url (lambda (h) (with-input-from-string h (lambda () (feed-parse (current-input-port) make-rss make-channel make-item)))))) ( ( :include "hop-foldlist" (