;;; Functions for xml processing. ;;; ;; file->xexpr: string --> xexpr ;; (file->xexpr filename) ;; Given a filename of a file in xml format, return the corresponding xml string. ;; ;; file->xexpr: string boolean --> xexpr ;; (file->xexpr filename attrs-as-tags?) ;; As before, but the if the boolean "attrs-as-tags" is false, ;; then the any tagged-xexpr has as its second item ;; an association list. ;; xexpr->file: xexpr string boolean --> true ;; (xexpr->file xexpr filename overwrite?) ;; Write xexpr to the indicated filename, in xml format. ;; The boolean indicates whether or not to overwrite the file, ;; if it already exists. ;; Side-effect: A text message is displayed, indicating ;; the file has been written. ;; WARNING: if overwrite? is true, any existing copy ;; of the file will be overwritten! ;; ;; xexpr->file: xexpr string boolean boolean boolean --> true ;; (xexpr->file fname xexpr attrs-as-tags? overwrite? verbose?) ;; As before, but include flags for whether or not ;; to to interpret "attr" tags as attributes, and ;; whether or not to display the file's-been-written message. ;; current-date-string: boolean --> string ;; (current-date-string include-time?) ;; Return the string representation of the current date; ;; include the time if the argument is true. ;; ;;;;; The implementation lies in xexpr210-body.ss ;;;;; (the rest of this file is the glue that lets this be used as a teachpack). ;; DrScheme v200 will simplify teachpacks (as any other module). ;; So don't worry about this magic: ;; (require-library "xmls.ss" "xml") ;; This gives us the signature xml^. (define-signature xexpr210^ (file->xexpr xexpr->file current-date-string)) (define xexpr210-unit (unit/sig xexpr210^ (import plt:userspace^ xml^) ; Now, the implementation: (include "xexpr210-body.ss"))) ;; At this point, xexpr210-unit is a single unit. ;; If you ever want to use it, you must provide ;; actual implementations of the functions it imports -- ;; namely those in plt:userspace^, xml^. ;; Let's roll together the unit we just made with the imports it needs. ;; (compound-unit/sig (import (p : plt:userspace^)) ; p is a formal argument. (link [ xml : xml^ ((require-library "xmlr.ss" "xml") (p : mzlib:function^)) ] [ xexpr210-bound-unit : xexpr210^ (xexpr210-unit p xml) ]) (export (open xexpr210-bound-unit))) #| ;; v200 will simplify teachpacks (as any other module). ;; So don't worry about this magic: ;; How compound-unit/sig works. We want to take in two units (namely xexpr210.ss, and xml.ss), and wrap them into a single compound unit. Note: xexpr210-body.ss requires the libraries file.ss and function.ss. However, these lbiraries are both subsumed inside plt:userspace^, whew! So it's only xml.ss that remains to be loaded by xexpr210-body.ss. imports: Thus this compound-unit imports plt:userspace^, and binds it to the name "p". links: the line [xml : xml^ (...)] "xml" is our name for the unit -- it's the formal parameter. The first thing after the colon is the signature for that library, xml^. It's saying, "xml" is what we'll call the unit provided to us; it had better match the signature "xml^". (That's why we loaded xmls.ss, to get that signature.) Then, the third part is the actual unit which we provide (to be called "xml"): We need to provide with a unit whose imports are already satisfied. The syntax is: (unit import1 import2 ...) So the require-library returns the xml unit, and looking at xml lib's documentation (or, inside xmlr.ss), we see that the xml library requires the mzlib:function^ library. So we need to provide that to the unit as an import. Fortunately, plt:userspace^ (which we previously bound to "p") contains this and more; "(p : mzlib:function^)" means "project p down to the mzlib:function^ sig.". Similarly, for xml-tt: that's our new name for a unit; the unit is xml-tt^ (defined above), and by looking at its imports we see it requries (units whose signature matches) plt:userspace^ and xml^ (in that order), so we prove those units. Finally, we export: open up xml-tt, and return the unit with those functions. |#