aboutsummaryrefslogtreecommitdiff
path: root/module/sxml/namespaced/util.scm
blob: e60254b760cb02e1ba1608e629b78b160ab07e0e (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
(define-module (sxml namespaced util)
  :use-module (sxml namespaced)
  :use-module (srfi srfi-1)
  :use-module ((ice-9 control) :select (call/ec))
  :use-module (hnh util type)
  :export (xml-element-hash-key
           find-child
           element-matches?
           root-element
           ))

(define (xml-element-hash-key tag)
  "Returns a value suitable as a key to hash-ref (and family)"
  (cons (xml-element-namespace tag)
        (xml-element-tagname tag)))

(define (find-child target list)
  (typecheck target xml-element?)
  (typecheck list (list-of (or xml-element? string?)))
  (define target* (xml-element-hash-key target))
  (find (lambda (x) (and (xml-element? x)
                    (equal? target* (xml-element-hash-key x))))
        list))


(define (element-matches? target-el tree)
  (and (not (null? tree))
       (equal?
        (xml-element-hash-key target-el)
        (xml-element-hash-key (car tree)))))