unofficial mirror of emacs-devel@gnu.org 
 help / color / mirror / code / Atom feed
* xml.el: xml-get-attribute returns "" if not found
@ 2003-11-12 21:28 Magnus Henoch
  2003-11-24  7:59 ` Juri Linkov
  0 siblings, 1 reply; 5+ messages in thread
From: Magnus Henoch @ 2003-11-12 21:28 UTC (permalink / raw)


Hi,

In lisp/xml.el, the function xml-get-attribute returns "" if the requested
attribute does not exist.  To me it seems that returning nil would make
more sense in that case.  Backwards compatibilty could be achieved with
something like this:

--- xml.el.old	Mon Nov  3 22:52:15 2003
+++ xml.el	Tue Nov  4 16:53:36 2003
@@ -104,15 +104,24 @@
 	      (push child match))))
     (nreverse match)))
 
-(defun xml-get-attribute (node attribute)
+(defun xml-get-attribute-or-nil (node attribute)
   "Get from NODE the value of ATTRIBUTE.
-An empty string is returned if the attribute was not found."
+nil is returned if the attribute was not found.
+
+See also `xml-get-attribute'."
   (if (xml-node-attributes node)
       (let ((value (assoc attribute (xml-node-attributes node))))
 	(if value
 	    (cdr value)
-	  ""))
-    ""))
+	  nil))
+    nil))
+
+(defsubst xml-get-attribute (node attribute)
+  "Get from NODE the value of ATTRIBUTE.
+An empty string is returned if the attribute was not found.
+
+See also `xml-get-attribute-or-nil'."
+  (or (xml-get-attribute-or-nil node attribute) ""))
 
 ;;*******************************************************************
 ;;**

What do you think about it?

Regards,
Magnus Henoch

^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2003-11-24 18:09 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2003-11-12 21:28 xml.el: xml-get-attribute returns "" if not found Magnus Henoch
2003-11-24  7:59 ` Juri Linkov
2003-11-24 13:29   ` Magnus Henoch
2003-11-24 15:40   ` Mark A. Hershberger
2003-11-24 18:09     ` Magnus Henoch

Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/emacs.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).