Index: /trunk/BookmarkApp.pm
===================================================================
--- /trunk/BookmarkApp.pm	(revision 18)
+++ /trunk/BookmarkApp.pm	(revision 19)
@@ -7,4 +7,5 @@
 
 use Encode;
+use HTTP::Date qw{time2isoz};
 use JSON;
 use Bookmarks;
@@ -88,4 +89,36 @@
             })
         );
+    } elsif ($format eq 'xbel') {
+        require XML::XBEL;
+        #TODO: conditional support; if XML::XBEL is not present, return a 5xx response
+
+        my $xbel = XML::XBEL->new;
+
+        $xbel->new_document({
+            title => 'Bookmarks' . ($tag ? " tagged as $tag" : ''),
+        });
+
+        for my $bookmark (@resources) {
+            my $cdatetime = time2isoz $bookmark->{ctime};
+            my $mdatetime = time2isoz $bookmark->{mtime};
+            # make the timestamps W3C-correct
+            s/ /T/ foreach ($cdatetime, $mdatetime);
+
+            $xbel->add_bookmark({
+                href     => $bookmark->{uri},
+                title    => $bookmark->{title},
+                desc     => 'Tags: ' . join(', ', @{ $bookmark->{tags} }),
+                added    => $cdatetime,
+                #XXX: are we sure that modified is the mtime of the bookmark or the resource?
+                modified => $mdatetime,
+            });
+        }
+
+        $self->header_props(
+            -type    => 'application/xml',
+            -charset => 'UTF-8',
+        );
+
+        return $xbel->toString;
     } else {
         $self->header_props(
