From mboxrd@z Thu Jan 1 00:00:00 1970 Path: main.gmane.org!not-for-mail From: mah@everybody.org (Mark A. Hershberger) Newsgroups: gmane.emacs.devel Subject: Re: xml.el: xml-get-attribute returns "" if not found Date: Mon, 24 Nov 2003 09:40:41 -0600 Sender: emacs-devel-bounces+emacs-devel=quimby.gnus.org@gnu.org Message-ID: <873ccdn5ae.fsf@weblog.localhost> References: <20031112212819.GA24650@anastasis.stor.no-ip.org> <8765hanot8.fsf@mail.jurta.org> NNTP-Posting-Host: deer.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii X-Trace: sea.gmane.org 1069689431 6683 80.91.224.253 (24 Nov 2003 15:57:11 GMT) X-Complaints-To: usenet@sea.gmane.org NNTP-Posting-Date: Mon, 24 Nov 2003 15:57:11 +0000 (UTC) Original-X-From: emacs-devel-bounces+emacs-devel=quimby.gnus.org@gnu.org Mon Nov 24 16:57:08 2003 Return-path: Original-Received: from quimby.gnus.org ([80.91.224.244]) by deer.gmane.org with esmtp (Exim 3.35 #1 (Debian)) id 1AOJ5I-000238-00 for ; Mon, 24 Nov 2003 16:57:08 +0100 Original-Received: from monty-python.gnu.org ([199.232.76.173]) by quimby.gnus.org with esmtp (Exim 3.35 #1 (Debian)) id 1AOJ5H-0003m5-00 for ; Mon, 24 Nov 2003 16:57:08 +0100 Original-Received: from localhost ([127.0.0.1] helo=monty-python.gnu.org) by monty-python.gnu.org with esmtp (Exim 4.24) id 1AOK1T-0005an-Mc for emacs-devel@quimby.gnus.org; Mon, 24 Nov 2003 11:57:15 -0500 Original-Received: from list by monty-python.gnu.org with tmda-scanned (Exim 4.24) id 1AOK0y-0005Zs-7I for emacs-devel@gnu.org; Mon, 24 Nov 2003 11:56:44 -0500 Original-Received: from mail by monty-python.gnu.org with spam-scanned (Exim 4.24) id 1AOK0R-0005PY-PA for emacs-devel@gnu.org; Mon, 24 Nov 2003 11:56:43 -0500 Original-Received: from [199.232.41.8] (helo=mx20.gnu.org) by monty-python.gnu.org with esmtp (TLSv1:DES-CBC3-SHA:168) (Exim 4.24) id 1AOK0Q-0004zn-He for emacs-devel@gnu.org; Mon, 24 Nov 2003 11:56:10 -0500 Original-Received: from [204.251.8.130] (helo=superman.everybody.org) by mx20.gnu.org with esmtp (Exim 4.24) id 1AOJ2c-0004Yz-6s for emacs-devel@gnu.org; Mon, 24 Nov 2003 10:54:22 -0500 Original-Received: from [166.102.29.217] (helo=weblog.localhost.everybody.org) by superman.everybody.org with asmtp (Exim 3.35 #1 (Debian)) id 1AOJGe-0004IX-00 for ; Mon, 24 Nov 2003 10:08:53 -0600 Original-To: emacs-devel@gnu.org X-URL: http://mah.everybody.org/weblog/ In-Reply-To: <8765hanot8.fsf@mail.jurta.org> (Juri Linkov's message of "Mon, 24 Nov 2003 09:59:59 +0200") User-Agent: Gnus/5.1003 (Gnus v5.10.3) Emacs/21.3.50 (gnu/linux) X-BeenThere: emacs-devel@gnu.org X-Mailman-Version: 2.1.2 Precedence: list List-Id: Emacs development discussions. List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: emacs-devel-bounces+emacs-devel=quimby.gnus.org@gnu.org Xref: main.gmane.org gmane.emacs.devel:18084 X-Report-Spam: http://spam.gmane.org/gmane.emacs.devel:18084 Juri Linkov writes: > Magnus Henoch 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 * 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) "")) ;;******************************************************************* ;;**