EBoard 31: Processing XML

Approximate overview

  • Admin
  • Lab

Administrative stuff

Introductory notes

  • Today started with ITS complications. Whee!
  • Today’s lab is all new. Fingers crossed.
    • I did not test the tests. Expect updates.
  • Today’s theme song is “Let it Snow”
  • Clementines!

Friday PSA

  • Please be moderate.
  • Consent is essential.

Upcoming activities

Token Events

  • Coffee Chat with Prof. Eliott Friday at 5pm in her lab. “Dear students, If you are a first or second year student, I hope you had the chance to visit professor Weinman’s excellent talk last week. In case you would like to continue the conversation… Join me this Friday to chat about a CS major! I will be happy to share how different adventures brought me to CS.”
  • Football vs Cornell Saturday at noon
  • GSO Saturday at 2pm in Sebring-Lewis
  • Go to Ames to support the Ultimates team 9am-6pm Saturday and Sunday
  • Grinnell Singers Sunday at 2pm in Sebring-Lewis
  • ISO Food Bazaar Sunday the 14th.
  • Mentor session Sunday at 4pm.
  • Collegium Sunday the 21st at 2pm.

Other good things

Upcoming work

A Problem

  • Identical answers.
  • One student cites, the other doesn’t.
  • Please be careful.
  • I have not yet reported anyone; if this may apply to you, feel free to chat with me about it and we’ll see if we can avoid the report.

Q&A

Why do we map the procedure over the tree, rather than using remove-spaces directly on the list?

(define remove-spaces
  (lambda (val)
    (cond
      [(string? val)
       (string-replace val " " "")]
      [else
       val])))

Could you change the colors?

Yes, but I will do so later.

Lab

Reminder: It’s new, there will be issues.

Preliminaries

  • Meet partner
  • Install libraries
  • Download files: Lab, excerpt.html, excerpt.css
  • Review self checks
  • Get started!

During Lab

How many things will go wrong?

A lot!

(define no-comment
  (lambda (xml)
    (cond
      [(string? xml)
       xml]
      [(pair? xml)
       (cond
         [(eq? (car xml) '@)
          xml]
         [(eq? (car xml) 'q)
          ; Special case if we see an attribute after the 'q
          ; The thing after the q (cadr) uses an @
          ; (q (@ ...) ....) -> (q (@ ...) "No comment.")
          (if (and (pair? (cadr xml))
                   (equal? (caadr xml) '@))
              (list 'q (cadr xml) "No comment.")
              '(q "No comment."))]
         [else
          (map no-comment xml)])]
      [else
       xml])))
(define off-with-their-heads
  (lambda (xml)
    (cond
      [(string? xml)
       xml]
      [(pair? xml)
       (cond
         [(eq? (car xml) '@)
          xml]
         [(eq? (car xml) 'q)
          ; Special case if we see an attribute after the 'q
          ; The thing after the q (cadr) uses an @
          ; (q (@ ...) ....) -> (q (@ ...) "No comment.")
          (if (and (pair? (cadr xml))
                   (equal? (caadr xml) '@)
                   (class-is-red-queen? (cdadr xml)))
              (list 'q (cadr xml) "Off with their heads!")
              xml)]
         [else
          (map off-with-their-heads xml)])]
      [else
       xml])))

; Given an attribute list, determine whether any of the attributes
; is a class attribute with a value that includes "redqueen".
; Attributes likely has the form
; `((attribute value) (attribute value) (attribute value) ...)`.
(define class-is-red-queen?
  (lambda (attributes)
    (cond
      [(null? attributes)
       #f]
      [(and (pair? (car attributes))
            (equal? (caar attributes) 'class)
            (index-of (string-split (cadar attributes)) "redqueen" ))
       #t]
      [else
       (class-is-red-queen? (cdr attributes))])))

Post Lab