scheme shell
about
download
support
resources
docu
links
 
scsh.net

Send Xml Suspend

Here is some code for SUnet for sending XML ouput. Send-xml/suspend and send-xml/finish do what their twin brothers send-html/suspend and send-html/finish do, but set the Content-Type header of the HTTP response to "text/xml". The rules for transforming the SXML tree additionally support XML processing instructions. Something like
  '(*PI* xml "version=\"1.0\"")

becomes

  <?xml version="1.0">

in the output. A second example:

  (*PI* xml-stylesheet "href=\"foo.xsl\" type=\"text/xsl\"")

becomes

  <?xml-stylesheet href="foo.xsl" type="text/xsl"?>

Here is the code:

  (define processing-instruction-rule
    `(*PI* *preorder*
  	 . ,(lambda (tag . elems)
  	      `(,(string-append "<?" (symbol->string (car elems)) " ")
  		,@(cdr elems)
  		"?>"))))

(define xml-rules (cons processing-instruction-rule default-rules))

(define (make-xml-reponse xml-string) (make-surflet-response (status-code ok) "text/xml" '(("Cache-Control" . "no-cache")) xml-string))

(define (send-xml/suspend xml-tree-maker) (send/suspend (lambda (k-url) (make-xml-reponse (sxml->string (xml-tree-maker k-url) xml-rules)))))

(define (send-xml/finish xml-tree) (send (make-xml-reponse (sxml->string xml-tree xml-rules))))

And here is a module definition for this code:

  (define-structure send-xml
      (export send-xml/finish
  	    send-xml/suspend)
    (open scheme
  	surflets/sxml
  	surflets/my-sxml
  	surflet-handler/primitives
  	surflet-handler/responses)
    (files send-xml))

-Eric


SendXmlSuspend - raw wiki source | code snippets archive