From: mah@everybody.org (Mark A. Hershberger)
Subject: Re: xml.el: xml-get-attribute returns "" if not found
Date: Mon, 24 Nov 2003 09:40:41 -0600 [thread overview]
Message-ID: <873ccdn5ae.fsf@weblog.localhost> (raw)
In-Reply-To: <8765hanot8.fsf@mail.jurta.org> (Juri Linkov's message of "Mon, 24 Nov 2003 09:59:59 +0200")
Juri Linkov <juri@jurta.org> writes:
> Magnus Henoch <mange@freemail.hu> 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 <mah@everybody.org>
* 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) ""))
;;*******************************************************************
;;**
next prev parent reply other threads:[~2003-11-24 15:40 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
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 [this message]
2003-11-24 18:09 ` Magnus Henoch
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=873ccdn5ae.fsf@weblog.localhost \
--to=mah@everybody.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
Code repositories for project(s) associated with this external index
https://git.savannah.gnu.org/cgit/emacs.git
https://git.savannah.gnu.org/cgit/emacs/org-mode.git
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.