指定id属性の値をもつ要素を探す:klacks - lisp-cookbook-ja/common-lisp GitHub Wiki
下記の例では、属性idの値が'x'の要素を探します。
ライブラリの導入方法
(ql:quickload :cxml-klacks)
XML文字列
(defparameter *xml*
"<a xmlns='http://tips.lisp-users.org/common-lisp'><b>1</b><b id='x'>1</b><b id='y'>9</b><c>2</c></a>")
XML文章構築+処理
(do ((source (cxml:make-source *xml*)))
((null (klacks:find-element source "b")))
(let ((lname (klacks:current-lname source))
(id nil))
;; FIXME map-attributes はこの使い方で合っているのか
(klacks:map-attributes (lambda (&rest args)
(declare (dynamic-extent args))
(setq id (nth 3 args)))
source)
(klacks:find-event source :characters)
(when (string= "x" id)
(format t
"~A[@id='~A'] => ~A~%"
lname id (klacks:current-characters source)))))
;-> b[@id='x'] => 1
;
;=> NIL