#lang scheme (require 2htdp/batch-io) (provide (all-from-out 2htdp/batch-io)) (require xml/xml htdp/error) (provide xexpr-as-string ;; Xexpr -> String ;; turn the X-expression into a string read-xexpr ;; String -> Xexpr ;; given a file name (must exist in the same directory as the program), ;; read the (first piece of) XML in the file and turn into an X-expression ) (define (read-xexpr f) (define a (and (string? f) (regexp-match "\\.xml$" f) (file-exists? f))) (check-arg 'read-xexpr a "file name with extension .xml" "" f) (xml->xexpr (with-input-from-file f read-xml/element))) (define (xexpr-as-string x) (check-arg 'xexpr->string (and (pair? x) (xexpr? x)) 'xexpr "first" x) (call-with-output-string (curry display-xml/content (xexpr->xml x))))