[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: Problems with xml-parse-string
From: |
Chong Yidong |
Subject: |
Re: Problems with xml-parse-string |
Date: |
Fri, 24 Sep 2010 14:47:49 -0400 |
User-agent: |
Gnus/5.13 (Gnus v5.13) Emacs/24.0.50 (gnu/linux) |
Lars Magne Ingebrigtsen <address@hidden> 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.
- Re: Problems with xml-parse-string, (continued)
- Re: Problems with xml-parse-string, Wojciech Meyer, 2010/09/24
- Re: Problems with xml-parse-string, Lars Magne Ingebrigtsen, 2010/09/24
- Re: Problems with xml-parse-string, Chong Yidong, 2010/09/24
- Re: Problems with xml-parse-string, Lars Magne Ingebrigtsen, 2010/09/24
- Re: Problems with xml-parse-string, Chong Yidong, 2010/09/24
- Re: Problems with xml-parse-string, Lars Magne Ingebrigtsen, 2010/09/24
- Re: Problems with xml-parse-string, Wojciech Meyer, 2010/09/24
- Re: Problems with xml-parse-string, Frank Schmitt, 2010/09/24
- Re: Problems with xml-parse-string, Ted Zlatanov, 2010/09/24
- Re: Problems with xml-parse-string, Wojciech Meyer, 2010/09/24
- Re: Problems with xml-parse-string,
Chong Yidong <=
- Re: Problems with xml-parse-string, Chong Yidong, 2010/09/24
- Re: Problems with xml-parse-string, Wojciech Meyer, 2010/09/24
- Re: Problems with xml-parse-string, Lars Magne Ingebrigtsen, 2010/09/24
- Re: Problems with xml-parse-string, Chong Yidong, 2010/09/24
- Re: Problems with xml-parse-string, Lars Magne Ingebrigtsen, 2010/09/24
- Re: Problems with xml-parse-string, Chong Yidong, 2010/09/24
- Re: Problems with xml-parse-string, Lars Magne Ingebrigtsen, 2010/09/25
- Re: Problems with xml-parse-string, Eli Zaretskii, 2010/09/25
- Re: Problems with xml-parse-string, David Kastrup, 2010/09/25
- Re: Problems with xml-parse-string, Wojciech Meyer, 2010/09/25