;; copy and past this code into your solution file ;; ----------------------------------------------------------------------------- ;; the library of xexpr functions ;; An Xexpr.v2 is one of: ;; -- (cons Symbol [Listof SX.v2]) ;; -- (cons Symbol (cons [Listof Attribute] [Listof SX.v2])) ;; An Attribute has the shape: ;; (cons Symbol (cons String empty)) ;; An SX.v2 is one of: ;; -- String ;; -- Xexpr.v2 ;; Xexpr -> Symbol ;; retrieve the name of the element (define (xexpr-name xe) (first xe)) ;; Xexpr -> [Listof Attribute] ;; retrieve the list of attributes of @racket[xe] (define (xexpr-attributes xe) (local ((define optional-loa+content (rest xe))) (cond [(empty? optional-loa+content) '()] [else (local ((define possible-loa (first optional-loa+content))) (if (list-of-attributes? possible-loa) possible-loa '()))]))) ;; LoA-or-LoX -> Boolean ;; is the given value a list of attributes? (define (list-of-attributes? x) (cond [(empty? x) true] [else (local ((define possible-attribute (first x))) (cons? possible-attribute))])) ;; Xexpr -> [Listof Xexpr] ;; retrieve the content of an Xexpr (define (xexpr-content xe) (local ((define optional-loa+content (rest xe))) (cond [(empty? optional-loa+content) '()] [else (if (list-of-attributes? (first optional-loa+content)) (rest optional-loa+content) optional-loa+content)]))) (define MISSING "missing attribute") ;; [Listof Attribute] -> [Maybe String] ;; retrieve a specific attribute value from an XML element (define (attribute-value al a) (local ((define r (assq a al))) (if (boolean? r) #f (second r))))