Add element-content as a prereq to matching on an element's textual content
traversal/interface.lisp
Sun Dec 13 05:24:52 UTC 2009 pix@kepibu.org
* Add element-content as a prereq to matching on an element's textual content
--- old-Oh, Ducks!/traversal/interface.lisp 2015-10-28 07:24:00.000000000 +0000
+++ new-Oh, Ducks!/traversal/interface.lisp 2015-10-28 07:24:00.000000000 +0000
@@ -13,6 +13,13 @@
(:documentation "Returns the value of the attribute of element, or nil if no such attribute exists."))
(defgeneric element-type (element)
(:documentation "Returns the tag name (type) of element."))
+(defgeneric element-content (element)
+ (:documentation "Returns a string containing the contents of the element, if it contains only textual nodes, or a sequence containing all of the element's child nodes (textual nodes as strings, tag nodes as whatever they'd be under #'element-children).")
+ (:method :around ((element t))
+ (let ((val (call-next-method)))
+ (if (every #'stringp val)
+ (reduce (curry #'concatenate 'string) val)
+ val))))
;;; special accessors in case something special needs to happen