[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: xml.el: xml-get-attribute returns "" if not found
From: |
Mark A. Hershberger |
Subject: |
Re: xml.el: xml-get-attribute returns "" if not found |
Date: |
Mon, 24 Nov 2003 09:40:41 -0600 |
User-agent: |
Gnus/5.1003 (Gnus v5.10.3) Emacs/21.3.50 (gnu/linux) |
Juri Linkov <address@hidden> writes:
> Magnus Henoch <address@hidden> writes:
>> 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.
>
> Please, install this patch. The current function don't disambiguate
> between cases when XML attribute has an empty string as its value and
> when there are no such attribute at all. This patch correctly fixes
> this.
Someone mentioned that Magnus would have to papers on file to apply
the patch.
Here is a similar patch with equivalent functionality that I
created. Since I have papers on file, perhaps this one could be
applied?
2003-11-24 Mark A. Hershberger <address@hidden>
* xml.el (xml-get-attribute-or-nil): New function. Disambiguate
between an non-existant attribute and an empty attribute.
-(defun xml-get-attribute (node attribute)
- "Get from NODE the value of ATTRIBUTE.
-An empty string is returned if the attribute was not found."
- (if (xml-node-attributes node)
+(defun xml-get-attribute-or-nil (node attribute)
+ "Get the value of ATTRIBUTE from NODE.
+Returns nil if the attribute is not found.
+
+See also `xml-get-attribute'"
+ (when (xml-node-attributes node)
(let ((value (assoc attribute (xml-node-attributes node))))
- (if value
- (cdr value)
- ""))
- ""))
+ (when value
+ (cdr value)))))
+
+(defsubst xml-get-attribute (node attribute)
+ "Get the the value of ATTRIBUTE from NODE.
+Returns an empty string if the attribute is not found.
+
+See also `xml-get-attribute-or-nil'"
+ (or (xml-get-attribute-or-nil node attribute) ""))
;;*******************************************************************
;;**