[plt-scheme] xhtml generation
I've just committed a documentation fix to SVN. Those 'pcdata's are
supposed to be 'p-i's. Here's an example:
#lang scheme
(require xml)
(define a-pi (make-p-i #f #f "foo" "bar"))
(define a-p (make-prolog empty #f))
(define a-p/pi (make-prolog (list a-pi) #f))
(define a-d0
(make-document a-p (make-element #f #f 'html empty empty)
empty))
(define a-d1
(make-document a-p (make-element #f #f 'html empty empty)
(list a-pi)))
(define a-d2
(make-document a-p/pi (make-element #f #f 'html empty empty)
(list a-pi)))
(display-xml a-d0)
(display-xml a-d1)
(display-xml a-d2)
On Wed, Feb 18, 2009 at 12:15 PM, <synx13+plt at gmail.com> wrote:
> I've been trying to understand xhtml and xml in general a bit better,
> and was just poking around the xml module for ways to generate valid
> documents. Figure I might include what I've done so far. Thanks to some
> help from eli on Freenode it's working now. My goal's not so much to
> have a system that cannot produce an invalid document, but to at least
> have a system where it's possible to produce a valid document.
>
> One thing I'm still puzzling over is in the plt documentation, the
> prolog and document's "misc" structures claim they can be both pcdata
> and comments (though AFAIK only comments are allowed there), but pcdata
> seems to error out when I use it in those fields. That's why the
> pre-comments et al are checked to make sure they're all only comments.
>
>
> #lang scheme
>
> (require xml)
>
> (define (create-document head body (pre-comments null) (post-comments null) (tail-comments null))
> (make-document
> (apply
> make-prolog
> (cons (make-p-i #f #f "xml" "version=\"1.0\" encoding=\"UTF-8\"") pre-comments)
> (make-document-type 'html (make-external-dtd/public
> "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"
> "-//W3C//DTD XHTML 1.0 Strict//EN") #f)
> post-comments)
> (xexpr->xml
> `(html ((lang "en") (xml:lang "en") (xmlns "http://www.w3.org/1999/xhtml"))
> (head () ,head)
> (body () ,body)))
> tail-comments))
>
> (define (only-comments? l)
> (andmap comment? l))
>
> (provide/contract
> [create-document
> (->*
> (xexpr? xexpr?) (only-comments? only-comments? only-comments?) document?)])
> #lang scheme
> (require "xhtml.ss")
> (require xml)
>
> (display-xml (create-document '(title "beep") '(p () "content")))
> (display "\n---\n")
> (display-xml (create-document
> '(title "beep") '(p () "shmontent")
> (list (make-comment "Beep") (make-comment "Beep2"))
> (list (make-comment "Before the HTML"))
> (list (make-comment "tail1") (make-comment "tail2"))))
> _________________________________________________
> For list-related administrative tasks:
> http://list.cs.brown.edu/mailman/listinfo/plt-scheme
>
>
--
Jay McCarthy <jay at cs.byu.edu>
Assistant Professor / Brigham Young University
http://teammccarthy.org/jay
"The glory of God is Intelligence" - D&C 93