Search

Delicious bookmarks on my home page with XQuery

I've been an on-and-off user of Delicious for some years now.  The other day I came across an article (which I can't find now) by Christian Hellmann ( @codep08) in which he uses Javascript to embed selected Delicious bookmarks in his blog page.  His idea was to mark up the notes part of the bookmark to identify the label for a link. In the page, Javascript retrieves the JSON feed and creates a collection of links by replacing the label with the hyperlink.

I adapted this idea to get links to use on my desktop home page.  I copied Christian's idea so I now have this subset of bookmarks in which the link label is enclosed in curly braces.

http://www.delicious.com/morelysq/4blog

Insead of the JSON feed, I use the RSS feed 

http://feeds.delicious.com/v2/xml/morelysq/4blog

and process these with an XQuery script. This is running on an EC2 micro-instance I've started playing with:

http://184.73.216.20/exist/rest//db/apps/delicious/bookmarks.xq?tag=4blog

My first  XQuery script used string functions to construct the HTML links:



declare option exist:serialize "method=xhtml media-type=text/html";
let $tag := request:get-parameter("tag","4blog")
let $feed := doc(concat("http://feeds.delicious.com/v2/xml/morelysq/",$tag,"?count=50"))
return
  <div>
     {for $item in $feed//item
      let $link := $item/link
      let $description := $item/description
      return
        <div> 
             {substring-before($description,"{")}
            
             {substring-before(substring-after($description,"{"),"}")}
            
             {substring-after($description,"}")}
         </div>
     }
  </div>


 


I include the generated div in the HTML page using an iframe (blush).

The string functions look rather clumsy so I tried a regexp:



return
         util:parse(
             concat(
                "<div>",
                replace ($description, 
                          "\{(.*)\}",
                          concat(" $1 ")
                        ),
                "</div>"
                )
           )


 


 

Better I think but the code now depends on an eXist function to convert from string to XML. Why conversion between strings and XML (util:parse() and util:serialize() in eXist ) are not core Path functions I really dont know.

Thanks to Christian, my use of Delicious has been reinvigorated and now that I can re-use the bookmarks I'm more likely to personalise my bookmarks by writing notes.