1 ;;; nnrss.el --- interfacing with RSS
2 ;; Copyright (C) 2001, 2002, 2003, 2004 Free Software Foundation, Inc.
4 ;; Author: Shenghuo Zhu <zsh@cs.rochester.edu>
7 ;; This file is part of GNU Emacs.
9 ;; GNU Emacs is free software; you can redistribute it and/or modify
10 ;; it under the terms of the GNU General Public License as published
11 ;; by the Free Software Foundation; either version 2, or (at your
12 ;; option) any later version.
14 ;; GNU Emacs is distributed in the hope that it will be useful, but
15 ;; WITHOUT ANY WARRANTY; without even the implied warranty of
16 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17 ;; General Public License for more details.
19 ;; You should have received a copy of the GNU General Public License
20 ;; along with GNU Emacs; see the file COPYING. If not, write to the
21 ;; Free Software Foundation, Inc., 59 Temple Place - Suite 330,
22 ;; Boston, MA 02111-1307, USA.
28 (eval-when-compile (require 'cl))
42 (eval '(require 'xml))
46 (defvoo nnrss-directory (nnheader-concat gnus-directory "rss/")
47 "Where nnrss will save its files.")
49 ;; (group max rss-url)
50 (defvoo nnrss-server-data nil)
52 ;; (num timestamp url subject author date extra)
53 (defvoo nnrss-group-data nil)
54 (defvoo nnrss-group-max 0)
55 (defvoo nnrss-group-min 1)
56 (defvoo nnrss-group nil)
57 (defvoo nnrss-group-hashtb (make-hash-table :test 'equal))
58 (defvoo nnrss-status-string "")
60 (defconst nnrss-version "nnrss 1.0")
62 (defvar nnrss-group-alist '()
63 "List of RSS addresses.")
65 (defvar nnrss-use-local nil)
67 (defvar nnrss-description-field 'X-Gnus-Description
68 "Field name used for DESCRIPTION.
69 To use the description in headers, put this name into `nnmail-extra-headers'.")
71 (defvar nnrss-url-field 'X-Gnus-Url
72 "Field name used for URL.
73 To use the description in headers, put this name into `nnmail-extra-headers'.")
75 (defvar nnrss-content-function nil
76 "A function which is called in `nnrss-request-article'.
77 The arguments are (ENTRY GROUP ARTICLE).
78 ENTRY is the record of the current headline. GROUP is the group name.
79 ARTICLE is the article number of the current headline.")
81 (nnoo-define-basics nnrss)
83 ;;; Interface functions
85 (deffoo nnrss-retrieve-headers (articles &optional group server fetch-old)
86 (nnrss-possibly-change-group group server)
89 (set-buffer nntp-server-buffer)
91 (dolist (article articles)
92 (if (setq e (assq article nnrss-group-data))
93 (insert (number-to-string (car e)) "\t" ;; number
95 (nnrss-format-string (nth 3 e)) "")
98 (nnrss-format-string (nth 4 e))
103 (format "<%d@%s.nnrss>" (car e) group)
110 (memq nnrss-description-field
111 nnmail-extra-headers))
112 (concat (symbol-name nnrss-description-field)
114 (nnrss-format-string (nth 6 e))
118 (memq nnrss-url-field
119 nnmail-extra-headers))
120 (concat (symbol-name nnrss-url-field)
122 (nnrss-format-string (nth 2 e))
128 (deffoo nnrss-request-group (group &optional server dont-check)
129 (nnrss-possibly-change-group group server)
132 (nnrss-check-group group server)
133 (nnheader-report 'nnrss "Opened group %s" group)
135 "211 %d %d %d %s\n" nnrss-group-max nnrss-group-min nnrss-group-max
136 (prin1-to-string group)
139 (deffoo nnrss-close-group (group &optional server)
142 (deffoo nnrss-request-article (article &optional group server buffer)
143 (nnrss-possibly-change-group group server)
144 (let ((e (assq article nnrss-group-data))
145 (boundary "=-=-=-=-=-=-=-=-=-")
146 (nntp-server-buffer (or buffer nntp-server-buffer))
150 (with-current-buffer nntp-server-buffer
152 (goto-char (point-min))
153 (insert "Mime-Version: 1.0\nContent-Type: multipart/alternative; boundary=\"" boundary "\"\n")
155 (insert "Newsgroups: " group "\n"))
157 (insert "Subject: " (nnrss-format-string (nth 3 e)) "\n"))
159 (insert "From: " (nnrss-format-string (nth 4 e)) "\n"))
161 (insert "Date: " (nnrss-format-string (nth 5 e)) "\n"))
162 (insert "Message-ID: " (format "<%d@%s.nnrss>" (car e) group) "\n")
164 (let ((text (if (nth 6 e)
165 (nnrss-string-as-multibyte (nth 6 e))))
168 (insert "\n\n--" boundary "\nContent-Type: text/plain\n\n")
169 (let ((point (point)))
173 (while (search-forward "\n" nil t)
175 (goto-char (point-max))
179 (insert "\n\n--" boundary "\nContent-Type: text/html\n\n")
180 (let ((point (point)))
182 (insert "<html><head></head><body>\n" text "\n</body></html>")
184 (while (search-forward "\n" nil t)
186 (goto-char (point-max))
189 (insert "<p><a href=\"" link "\">link</a></p>\n"))))
190 (when nnrss-content-function
191 (funcall nnrss-content-function e group article)))))
194 (nnheader-report 'nnrss err))
196 (nnheader-report 'nnrss "no such id: %d" article))
198 (nnheader-report 'nnrss "article %s retrieved" (car e))
199 ;; we return the article number.
200 (cons nnrss-group (car e))))))
202 (deffoo nnrss-request-list (&optional server)
203 (nnrss-possibly-change-group nil server)
204 (nnrss-generate-active)
207 (deffoo nnrss-open-server (server &optional defs connectionless)
208 (nnrss-read-server-data server)
209 (nnoo-change-server 'nnrss server defs)
212 (deffoo nnrss-request-expire-articles
213 (articles group &optional server force)
214 (nnrss-possibly-change-group group server)
215 (let (e days not-expirable changed)
216 (dolist (art articles)
217 (if (and (setq e (assq art nnrss-group-data))
218 (nnmail-expired-article-p
220 (if (listp (setq days (nth 1 e))) days
221 (days-to-time (- days (time-to-days '(0 0)))))
223 (setq nnrss-group-data (delq e nnrss-group-data)
225 (push art not-expirable)))
227 (nnrss-save-group-data group server))
230 (deffoo nnrss-request-delete-group (group &optional force server)
231 (nnrss-possibly-change-group group server)
232 (setq nnrss-server-data
233 (delq (assoc group nnrss-server-data) nnrss-server-data))
234 (nnrss-save-server-data server)
236 (delete-file (nnrss-make-filename group server)))
239 (deffoo nnrss-request-list-newsgroups (&optional server)
240 (nnrss-possibly-change-group nil server)
242 (set-buffer nntp-server-buffer)
244 (dolist (elem nnrss-group-alist)
246 (insert (car elem) "\t" (third elem) "\n"))))
249 (nnoo-define-skeleton nnrss)
251 ;;; Internal functions
252 (eval-when-compile (defun xml-rpc-method-call (&rest args)))
253 (defun nnrss-fetch (url &optional local)
254 "Fetch URL and put it in a the expected Lisp structure."
256 ;;some CVS versions of url.el need this to close the connection quickly
257 (let (xmlform htmlform)
258 ;; bit o' work necessary for w3 pre-cvs and post-cvs
260 (let ((coding-system-for-read 'binary))
261 (insert-file-contents url))
264 ;; Because xml-parse-region can't deal with anything that isn't
265 ;; xml and w3-parse-buffer can't deal with some xml, we have to
266 ;; parse with xml-parse-region first and, if that fails, parse
267 ;; with w3-parse-buffer. Yuck. Eventually, someone should find out
268 ;; why w3-parse-buffer fails to parse some well-formed xml and
272 (setq xmlform (xml-parse-region (point-min) (point-max)))
273 (error (if (fboundp 'w3-parse-buffer)
274 (setq htmlform (caddar (w3-parse-buffer
276 (message "nnrss: Not valid XML and w3 parse not available (%s)"
282 (defun nnrss-possibly-change-group (&optional group server)
284 (not (nnrss-server-opened server)))
285 (nnrss-open-server server))
286 (when (and group (not (equal group nnrss-group)))
287 (nnrss-read-group-data group server)
288 (setq nnrss-group group)))
290 (defvar nnrss-extra-categories '(nnrss-snarf-moreover-categories))
292 (defun nnrss-generate-active ()
293 (if (y-or-n-p "Fetch extra categories? ")
294 (dolist (func nnrss-extra-categories)
297 (set-buffer nntp-server-buffer)
299 (dolist (elem nnrss-group-alist)
300 (insert (prin1-to-string (car elem)) " 0 1 y\n"))
301 (dolist (elem nnrss-server-data)
302 (unless (assoc (car elem) nnrss-group-alist)
303 (insert (prin1-to-string (car elem)) " 0 1 y\n")))))
307 (defun nnrss-read-server-data (server)
308 (setq nnrss-server-data nil)
309 (let ((file (nnrss-make-filename "nnrss" server)))
310 (when (file-exists-p file)
311 (let ((coding-system-for-read 'binary))
312 (load file nil nil t)))))
314 (defun nnrss-save-server-data (server)
315 (gnus-make-directory nnrss-directory)
316 (let ((coding-system-for-write 'binary))
317 (with-temp-file (nnrss-make-filename "nnrss" server)
318 (gnus-prin1 `(setq nnrss-group-alist ',nnrss-group-alist))
319 (gnus-prin1 `(setq nnrss-server-data ',nnrss-server-data)))))
321 (defun nnrss-read-group-data (group server)
322 (setq nnrss-group-data nil)
323 (if (hash-table-p nnrss-group-hashtb)
324 (clrhash nnrss-group-hashtb)
325 (setq nnrss-group-hashtb (make-hash-table :test 'equal)))
326 (let ((pair (assoc group nnrss-server-data)))
327 (setq nnrss-group-max (or (cadr pair) 0))
328 (setq nnrss-group-min (+ nnrss-group-max 1)))
329 (let ((file (nnrss-make-filename group server)))
330 (when (file-exists-p file)
331 (let ((coding-system-for-read 'binary))
333 (dolist (e nnrss-group-data)
334 (puthash (or (nth 2 e) (nth 6 e)) t nnrss-group-hashtb)
335 (when (and (car e) (> nnrss-group-min (car e)))
336 (setq nnrss-group-min (car e)))
337 (when (and (car e) (< nnrss-group-max (car e)))
338 (setq nnrss-group-max (car e)))))))
340 (defun nnrss-save-group-data (group server)
341 (gnus-make-directory nnrss-directory)
342 (let ((coding-system-for-write 'binary))
343 (with-temp-file (nnrss-make-filename group server)
344 (gnus-prin1 `(setq nnrss-group-data ',nnrss-group-data)))))
346 (defun nnrss-make-filename (name server)
348 (nnrss-translate-file-chars
351 (not (equal server ""))
357 (gnus-add-shutdown 'nnrss-close 'gnus)
359 (defun nnrss-close ()
360 "Clear internal nnrss variables."
361 (setq nnrss-group-data nil
362 nnrss-server-data nil
363 nnrss-group-hashtb nil
364 nnrss-group-alist nil))
368 (defun nnrss-no-cache (url)
371 (defun nnrss-insert-w3 (url)
372 (mm-with-unibyte-current-buffer
373 (mm-url-insert url)))
375 (defun nnrss-decode-entities-unibyte-string (string)
377 (mm-with-unibyte-buffer
379 (mm-url-decode-entities-nbsp)
382 (defalias 'nnrss-insert 'nnrss-insert-w3)
384 (if (featurep 'xemacs)
385 (defalias 'nnrss-string-as-multibyte 'identity)
386 (defalias 'nnrss-string-as-multibyte 'string-as-multibyte))
390 (defun nnrss-check-group (group server)
391 (let (file xml subject url extra changed author
392 date rss-ns rdf-ns content-ns dc-ns)
393 (if (and nnrss-use-local
394 (file-exists-p (setq file (expand-file-name
395 (nnrss-translate-file-chars
396 (concat group ".xml"))
398 (setq xml (nnrss-fetch file t))
399 (setq url (or (nth 2 (assoc group nnrss-server-data))
400 (second (assoc group nnrss-group-alist))))
407 (format "URL to search for %s: " group) "http://")))))
408 (let ((pair (assoc group nnrss-server-data)))
410 (setcdr (cdr pair) (list url))
411 (push (list group nnrss-group-max url) nnrss-server-data)))
413 (setq xml (nnrss-fetch url)))
415 ;; http://feeds.archive.org/validator/docs/howto/declare_namespaces.html
416 ;; for more RSS namespaces.
417 (setq dc-ns (nnrss-get-namespace-prefix xml "http://purl.org/dc/elements/1.1/")
418 rdf-ns (nnrss-get-namespace-prefix xml "http://www.w3.org/1999/02/22-rdf-syntax-ns#")
419 rss-ns (nnrss-get-namespace-prefix xml "http://purl.org/rss/1.0/")
420 content-ns (nnrss-get-namespace-prefix xml "http://purl.org/rss/1.0/modules/content/"))
421 (dolist (item (nreverse (nnrss-find-el (intern (concat rss-ns "item")) xml)))
422 (when (and (listp item)
423 (string= (concat rss-ns "item") (car item))
424 (if (setq url (nnrss-decode-entities-unibyte-string
425 (nnrss-node-text rss-ns 'link (cddr item))))
426 (not (gethash url nnrss-group-hashtb))
427 (setq extra (or (nnrss-node-text content-ns 'encoded item)
428 (nnrss-node-text rss-ns 'description item)))
429 (not (gethash extra nnrss-group-hashtb))))
430 (setq subject (nnrss-node-text rss-ns 'title item))
431 (setq extra (or extra
432 (nnrss-node-text content-ns 'encoded item)
433 (nnrss-node-text rss-ns 'description item)))
434 (setq author (or (nnrss-node-text rss-ns 'author item)
435 (nnrss-node-text dc-ns 'creator item)
436 (nnrss-node-text dc-ns 'contributor item)))
437 (setq date (or (nnrss-node-text dc-ns 'date item)
438 (nnrss-node-text rss-ns 'pubDate item)
439 (message-make-date)))
442 (incf nnrss-group-max)
445 (and subject (nnrss-decode-entities-unibyte-string subject))
446 (and author (nnrss-decode-entities-unibyte-string author))
448 (and extra (nnrss-decode-entities-unibyte-string extra)))
450 (puthash (or url extra) t nnrss-group-hashtb)
454 (nnrss-save-group-data group server)
455 (let ((pair (assoc group nnrss-server-data)))
457 (setcar (cdr pair) nnrss-group-max)
458 (push (list group nnrss-group-max) nnrss-server-data)))
459 (nnrss-save-server-data server))))
461 (defun nnrss-opml-import (opml-file)
462 "OPML subscriptions import.
463 Read the file and attempt to subscribe to each Feed in the file."
464 (interactive "fImport file: ")
466 (lambda (node) (gnus-group-make-rss-group
467 (cdr (assq 'xmlUrl (cadr node)))))
468 (nnrss-find-el 'outline
470 (find-file opml-file)
471 (xml-parse-region (point-min)
474 (defun nnrss-opml-export ()
475 "OPML subscription export.
476 Export subscriptions to a buffer in OPML Format."
478 (with-current-buffer (get-buffer-create "*OPML Export*")
479 (mm-set-buffer-file-coding-system 'utf-8)
481 "<?xml version=\"1.0\" encoding=\"utf-8\"?>\n"
482 "<!-- OPML generated by Emacs Gnus' nnrss.el -->\n"
483 "<opml version=\"1.1\">\n"
485 " <title>mySubscriptions</title>\n"
486 " <dateCreated>" (format-time-string "%a, %d %b %Y %T %z")
488 " <ownerEmail>" user-mail-address "</ownerEmail>\n"
489 " <ownerName>" (user-full-name) "</ownerName>\n"
494 " <outline text=\"" (car sub) "\" xmlUrl=\""
495 (cadr sub) "\"/>\n")))
500 (pop-to-buffer "*OPML Export*")
501 (when (fboundp 'sgml-mode)
504 (defun nnrss-generate-download-script ()
505 "Generate a download script in the current buffer.
506 It is useful when `(setq nnrss-use-local t)'."
508 (insert "#!/bin/sh\n")
509 (insert "WGET=wget\n")
510 (insert "RSSDIR='" (expand-file-name nnrss-directory) "'\n")
511 (dolist (elem nnrss-server-data)
512 (let ((url (or (nth 2 elem)
513 (second (assoc (car elem) nnrss-group-alist)))))
514 (insert "$WGET -q -O \"$RSSDIR\"/'"
515 (nnrss-translate-file-chars (concat (car elem) ".xml"))
518 (defun nnrss-translate-file-chars (name)
519 (let ((nnheader-file-name-translation-alist
520 (append nnheader-file-name-translation-alist '((?' . ?_)))))
521 (nnheader-translate-file-chars name)))
523 (defvar nnrss-moreover-url
524 "http://w.moreover.com/categories/category_list_rss.html"
525 "The url of moreover.com categories.")
527 (defun nnrss-snarf-moreover-categories ()
528 "Snarf RSS links from moreover.com."
530 (let (category name url changed)
532 (nnrss-insert nnrss-moreover-url)
533 (goto-char (point-min))
534 (while (re-search-forward
535 "<a name=\"\\([^\"]+\\)\">\\|<a href=\"\\(http://[^\"]*moreover\\.com[^\"]+page\\?c=\\([^\"&]+\\)&o=rss\\)" nil t)
537 (setq category (match-string 1))
538 (setq url (match-string 2)
539 name (mm-url-decode-entities-string
540 (rfc2231-decode-encoded-string
543 (setq name (concat category "." name)))
544 (unless (assoc name nnrss-server-data)
546 (push (list name 0 url) nnrss-server-data)))))
548 (nnrss-save-server-data ""))))
550 (defun nnrss-format-string (string)
551 (gnus-replace-in-string (nnrss-string-as-multibyte string) " *\n *" " "))
553 (defun nnrss-node-text (namespace local-name element)
554 (let* ((node (assq (intern (concat namespace (symbol-name local-name)))
556 (text (if (and node (listp node))
557 (nnrss-node-just-text node)
559 (cleaned-text (if text (gnus-replace-in-string
560 text "^[\000-\037\177]+\\|^ +\\| +$" ""))))
561 (if (string-equal "" cleaned-text)
565 (defun nnrss-node-just-text (node)
566 (if (and node (listp node))
567 (mapconcat 'nnrss-node-just-text (cddr node) " ")
570 (defun nnrss-find-el (tag data &optional found-list)
571 "Find the all matching elements in the data.
572 Careful with this on large documents!"
576 (when (equal tag (car bit))
580 (if (and (listp (car-safe (caddr bit)))
581 (not (stringp (caddr bit))))
593 (defun nnrss-rsslink-p (el)
594 "Test if the element we are handed is an RSS autodiscovery link."
595 (and (eq (car-safe el) 'link)
596 (string-equal (cdr (assoc 'rel (cadr el))) "alternate")
597 (or (string-equal (cdr (assoc 'type (cadr el)))
598 "application/rss+xml")
599 (string-equal (cdr (assoc 'type (cadr el))) "text/xml"))))
601 (defun nnrss-get-rsslinks (data)
602 "Extract the <link> elements that are links to RSS from the parsed data."
605 (if (nnrss-rsslink-p el) el))
606 (nnrss-find-el 'link data))))
608 (defun nnrss-extract-hrefs (data)
609 "Recursively extract hrefs from a page's source.
610 DATA should be the output of `xml-parse-region' or
612 (mapcar (lambda (ahref)
613 (cdr (assoc 'href (cadr ahref))))
614 (nnrss-find-el 'a data)))
616 (defmacro nnrss-match-macro (base-uri item
617 onsite-list offsite-list)
618 `(cond ((or (string-match (concat "^" ,base-uri) ,item)
619 (not (string-match "://" ,item)))
620 (setq ,onsite-list (append ,onsite-list (list ,item))))
621 (t (setq ,offsite-list (append ,offsite-list (list ,item))))))
623 (defun nnrss-order-hrefs (base-uri hrefs)
624 "Given a list of hrefs, sort them using the following priorities:
625 1. links ending in .rss
626 2. links ending in .rdf
627 3. links ending in .xml
628 4. links containing the above
631 BASE-URI is used to determine the location of the links and
632 whether they are `offsite' or `onsite'."
633 (let (rss-onsite-end rdf-onsite-end xml-onsite-end
634 rss-onsite-in rdf-onsite-in xml-onsite-in
635 rss-offsite-end rdf-offsite-end xml-offsite-end
636 rss-offsite-in rdf-offsite-in xml-offsite-in)
638 (if (not (null href))
639 (cond ((string-match "\\.rss$" href)
641 base-uri href rss-onsite-end rss-offsite-end))
642 ((string-match "\\.rdf$" href)
644 base-uri href rdf-onsite-end rdf-offsite-end))
645 ((string-match "\\.xml$" href)
647 base-uri href xml-onsite-end xml-offsite-end))
648 ((string-match "rss" href)
650 base-uri href rss-onsite-in rss-offsite-in))
651 ((string-match "rdf" href)
653 base-uri href rdf-onsite-in rdf-offsite-in))
654 ((string-match "xml" href)
656 base-uri href xml-onsite-in xml-offsite-in)))))
659 rss-onsite-end rdf-onsite-end xml-onsite-end
660 rss-onsite-in rdf-onsite-in xml-onsite-in
661 rss-offsite-end rdf-offsite-end xml-offsite-end
662 rss-offsite-in rdf-offsite-in xml-offsite-in)))
664 (defun nnrss-discover-feed (url)
665 "Given a page, find an RSS feed using Mark Pilgrim's
666 `ultra-liberal rss locator' (http://diveintomark.org/2002/08/15.html)."
668 (let ((parsed-page (nnrss-fetch url)))
670 ;; 1. if this url is the rss, use it.
671 (if (nnrss-rss-p parsed-page)
672 (let ((rss-ns (nnrss-get-namespace-prefix parsed-page "http://purl.org/rss/1.0/")))
673 (nnrss-rss-title-description rss-ns parsed-page url))
675 ;; 2. look for the <link rel="alternate"
676 ;; type="application/rss+xml" and use that if it is there.
677 (let ((links (nnrss-get-rsslinks parsed-page)))
679 (let* ((xml (nnrss-fetch
680 (cdr (assoc 'href (cadar links)))))
681 (rss-ns (nnrss-get-namespace-prefix xml "http://purl.org/rss/1.0/")))
682 (nnrss-rss-title-description rss-ns xml (cdr (assoc 'href (cadar links)))))
684 ;; 3. look for links on the site in the following order:
685 ;; - onsite links ending in .rss, .rdf, or .xml
686 ;; - onsite links containing any of the above
687 ;; - offsite links ending in .rss, .rdf, or .xml
688 ;; - offsite links containing any of the above
689 (let* ((base-uri (progn (string-match ".*://[^/]+/?" url)
690 (match-string 0 url)))
691 (hrefs (nnrss-order-hrefs
692 base-uri (nnrss-extract-hrefs parsed-page)))
694 (while (and (eq rss-link nil) (not (eq hrefs nil)))
695 (let ((href-data (nnrss-fetch (car hrefs))))
696 (if (nnrss-rss-p href-data)
697 (let* ((rss-ns (nnrss-get-namespace-prefix href-data "http://purl.org/rss/1.0/")))
698 (setq rss-link (nnrss-rss-title-description
699 rss-ns href-data (car hrefs))))
700 (setq hrefs (cdr hrefs)))))
701 (if rss-link rss-link
704 (nnrss-find-rss-via-syndic8 url))))))))
706 (defun nnrss-find-rss-via-syndic8 (url)
707 "Query syndic8 for the rss feeds it has for URL."
708 (if (not (locate-library "xml-rpc"))
710 (message "XML-RPC is not available... not checking Syndic8.")
713 (let ((feedid (xml-rpc-method-call
714 "http://www.syndic8.com/xmlrpc.php"
718 (let* ((feedinfo (xml-rpc-method-call
719 "http://www.syndic8.com/xmlrpc.php"
727 (cdr (assoc "status" listinfo))
730 (cdr (assoc "sitename" listinfo))
734 "sitename" listinfo)))
737 "dataurl" listinfo)))))))
739 (if (not (> (length urllist) 1))
741 (let ((completion-ignore-case t)
743 (mapcar (lambda (listinfo)
744 (cons (cdr (assoc "sitename" listinfo))
746 (cdr (assoc "feedid" listinfo)))))
750 "Multiple feeds found. Select one: "
751 selection nil t) urllist)))))))))
753 (defun nnrss-rss-p (data)
754 "Test if DATA is an RSS feed.
755 Simply ensures that the first element is rss or rdf."
756 (or (eq (caar data) 'rss)
757 (eq (caar data) 'rdf:RDF)))
759 (defun nnrss-rss-title-description (rss-namespace data url)
760 "Return the title of an RSS feed."
761 (if (nnrss-rss-p data)
762 (let ((description (intern (concat rss-namespace "description")))
763 (title (intern (concat rss-namespace "title")))
764 (channel (nnrss-find-el (intern (concat rss-namespace "channel"))
767 (cons 'description (caddr (nth 0 (nnrss-find-el description channel))))
768 (cons 'title (caddr (nth 0 (nnrss-find-el title channel))))
771 (defun nnrss-get-namespace-prefix (el uri)
772 "Given EL (containing a parsed element) and URI (containing a string
773 that gives the URI for which you want to retrieve the namespace
774 prefix), return the prefix."
775 (let* ((prefix (car (rassoc uri (cadar el))))
777 (split-string (symbol-name prefix) ":")))
778 (ns (cond ((eq (length nslist) 1) ; no prefix given
780 ((eq (length nslist) 2) ; extract prefix
782 (if (and ns (not (string= ns "")))
789 ;;; nnrss.el ends here