From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Chong Yidong Newsgroups: gmane.emacs.devel Subject: Re: Problems with xml-parse-string Date: Fri, 24 Sep 2010 14:47:49 -0400 Message-ID: <87iq1v0yi2.fsf@stupidchicken.com> References: <87zkvaiked.fsf@stupidchicken.com> <87vd5ymptn.fsf@stupidchicken.com> <87vd5x7ty2.fsf@stupidchicken.com> <87vd5wo48a.fsf@stupidchicken.com> <8739t03q2g.fsf@stupidchicken.com> <87k4mb2mfu.fsf@stupidchicken.com> <87pqw3nm4y.fsf@stupidchicken.com> NNTP-Posting-Host: lo.gmane.org Mime-Version: 1.0 Content-Type: text/plain X-Trace: dough.gmane.org 1285354088 10638 80.91.229.12 (24 Sep 2010 18:48:08 GMT) X-Complaints-To: usenet@dough.gmane.org NNTP-Posting-Date: Fri, 24 Sep 2010 18:48:08 +0000 (UTC) To: emacs-devel@gnu.org Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Fri Sep 24 20:48:07 2010 Return-path: Envelope-to: ged-emacs-devel@m.gmane.org Original-Received: from lists.gnu.org ([199.232.76.165]) by lo.gmane.org with esmtp (Exim 4.69) (envelope-from ) id 1OzDJV-00012E-NR for ged-emacs-devel@m.gmane.org; Fri, 24 Sep 2010 20:48:06 +0200 Original-Received: from localhost ([127.0.0.1]:57878 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1OzDJV-0005ce-3u for ged-emacs-devel@m.gmane.org; Fri, 24 Sep 2010 14:48:05 -0400 Original-Received: from [140.186.70.92] (port=45820 helo=eggs.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1OzDJM-0005cY-T3 for emacs-devel@gnu.org; Fri, 24 Sep 2010 14:47:59 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.69) (envelope-from ) id 1OzDJI-0005Gx-NG for emacs-devel@gnu.org; Fri, 24 Sep 2010 14:47:56 -0400 Original-Received: from pantheon-po43.its.yale.edu ([130.132.50.104]:52708) by eggs.gnu.org with esmtp (Exim 4.69) (envelope-from ) id 1OzDJI-0005Gg-Li for emacs-devel@gnu.org; Fri, 24 Sep 2010 14:47:52 -0400 Original-Received: from furry (dhcp128036014154.central.yale.edu [128.36.14.154]) (authenticated bits=0) by pantheon-po43.its.yale.edu (8.12.11.20060308/8.12.11) with ESMTP id o8OIlodE010070 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=NOT) for ; Fri, 24 Sep 2010 14:47:50 -0400 Original-Received: by furry (Postfix, from userid 1000) id EBC1716D402; Fri, 24 Sep 2010 14:47:49 -0400 (EDT) In-Reply-To: (Lars Magne Ingebrigtsen's message of "Fri, 24 Sep 2010 18:46:11 +0200") User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/24.0.50 (gnu/linux) X-YaleITSMailFilter: Version 1.2c (attachment(s) not renamed) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.4-2.6 X-BeenThere: emacs-devel@gnu.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: "Emacs development discussions." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Original-Sender: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Errors-To: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Xref: news.gmane.org gmane.emacs.devel:130793 Archived-At: Lars Magne Ingebrigtsen writes: > Here's a pretty piece of code, chosen at random: > > (defun nnrss-find-el (tag data &optional found-list) > ... > The horror! I think that code might just be crufty. Here's an implementation, assuming sxml format: (defun nnrss-find-el (tag data &optional found-list) "Find the all matching elements in the data. Careful with this on large documents!" (nreverse (nnrss-find-el-1 tag data))) (defun nnrss-find-el-1 (tag data &optional found-list) (and (consp data) (not (eq (car data) '@)) (if (equal tag (car data)) (push data found-list) (dolist (bit (cdr data)) (setq found-list (nnrss-find-el-1 tag bit found-list))))) found-list) Doesn't seem too horrific. Here's the example tree: (setq test-sxml-tree '(tag (@ (attr1 "value1") (attr2 "value2")) "Free text" (foo "Text node 1") (bar "Text node 2") (baz "More free text" (foo "Text node 3") (bar "Text node 4")))) > To take a concrete example: You want the src of the img node you have. > > xml.el: (cdr (assq 'img (cadr node))) > sxml.el: (if (and (consp (cadr node)) > (eq (caadr node) '@)) > (cadr (assq 'img node))) > > (And I'm not even sure that's correct. It's probably not. Which is my > point.) > > libxml: (cdr (assq :img (cdr node))) > > (The difference between libxml and xml.c for attributes is minuscule.) I think this example is confused. If you're scanning at top-level, without descent, the code for all three cases is practically identical: it's a simple assq.