On Jul 14, 2009, at 11:25 AM, Paul M wrote:
Hi:
Just wondering if there are existing xqy functions/modules available
to generate RSS/Atom feeds. I did notice that MarkLogic provides a
reader.
-Paul
It's actually very easy in MarkLogic to generate Atom feeds. With
MarkMail.org for example you can get any query result at an Atom
feed. It took an afternoon to write. About 2 hours to learn the
format, 1 hour to type the code, and 2 hours to make sure our CSS in
the item's body worked across different viewers. Here's most of the
code behind that:
(: Assume you have some cts:query named $cts, a query $q, etc :)
(: I'll use ..... in some places to indicate places you can fill in
your details :)
(: This code uses some rendering functions not shown here. :)
let $messages := (
for $m in cts:search(collection("messages")/message, $cts)
order by xs:dateTime($m/@date) descending
return $m
)[1 to $max]
<feed xmlns="http://www.w3.org/2005/Atom">
<title>MarkMail: { $q }</title>
<subtitle>We've Got Mail!</subtitle>
<link href="....." rel="self"/>
<updated>{ current-dateTime() }</updated>
<id>...</id>
<generator uri="http://markmail.org/atom" version="1.0">MarkMail</
generator>
<icon>http://markmail.org/favicon.ico</icon>
<logo>http://markmail.org/images/logo_red.gif</logo>
{
(: no author :)
(: no id :)
}
{
for $m in $messages
return
<entry>
<id>urn:uuid:markmail-{ string($m/@id) }</id>
<link href="....."/>
<title>{ display($m/headers/subject) }</title>
<author><name>{
util:emailObfuscate(display($m/headers/from/
@personal))
}</name></author>
<updated>{ string($m/@date) }</updated>
<published>{ string($m/@date) }</published>
<content type="html">{ xdmp:quote(
<div xmlns="intentional">{
atomlib:renderMessage($m, <search xmlns=""/>)
}</div>
) }</content>
</entry>
}
</feed>
The only real interesting part is the "intentional" namespace hack
which we employed to help various readers understand the resulting
feed. I forget the details of which ones this helped.
You can calculate $max based on time or size or both, like the last 50
feeds unless there were more than 50 in the last hour in which case
give everything for the last hour. We use a reverse proxy in front so
we only regenerate a feed every 57 minutes no matter how often it's
requested.
Anyway, that's the basic sketch of generating an Atom feed with
MarkLogic Server.
You can see it in action here:
http://markmail.org/atom/?q=list:marklogic
-jh-
_______________________________________________
General mailing list
[email protected]
http://xqzone.com/mailman/listinfo/general