A sample page for the XHTML module

Readme

The following is imported verbatim from the README file, as ca be seen in the source code of this page below.

XHTML is a O'Caml module for creating valid XHTML 1.1 (and XHTML 1.0) documents. The validity of the pages is guaranteed by the O'Caml type system. (NB: at the time of writing, forms support was not complete, only basic forms are implemented. Image maps are also not implemented yet.)

XHTML can be used for creating static documents, but it is not the most conventient way to key in text heavy documents. Instead, it should be most useful for database frontends etc.

XHTML is not a general XML processor that parses a DTD and checks the validity of a document with respect to this DTD. This lack in flexibility is made up for by the ability to perform prove validity by static type checking.

The implementation uses a XML module for generating well formed---but not necessarily valid with respect to some DTD---XML documents. The elements of type XML.elt and attributes of type XML.attrib are then hidden behind polymorphic phantom types type 'a elt = XML.elt and type 'a attrib = XML.attrib with 'a set to appropriate polymorphic variants.

This approach can be adopted easily to other XML document types: MathML and MusicML come to mind.

$Id: README,v 1.3 2004/01/28 09:20:34 ohl Exp $

Example

This is a recursive example that contains its own description …

Code

(* $Id: homepage.ml,v 1.6 2005/06/20 17:57:58 ohl Exp $ *)

let self = "examples/homepage.ml"

let file_to_string name =
  let ic = open_in name in
  let len = in_channel_length ic in
  let s = String.create len in
  really_input ic s 0 len;
  close_in ic;
  s

let paragraph_separator = Str.regexp "\n\n+"

let file_to_paragraphs name =
  Str.split paragraph_separator (file_to_string name)

open XHTML.M

let href url elts =
  a ~a:[a_href url] elts

let file name =
  href name [code [pcdata name]]

let valid_xhtml ?url ~name ~email () =
  table ~a:[a_width (`Percent 100)]
    (tr
       (td [pcdata "This WWW page is brought to you by ";
	    (match url with None -> pcdata name | Some u -> href u [pcdata name]);
	    pcdata " "; href ("email:" ^ email) [pcdata ("<" ^ email ^ ">")];
	    pcdata ".  It is valid "; href standard [pcdata version];
	    pcdata ", as can be verified online by going to the ";
	    href "http://www.w3.org/" [pcdata "W3C"]; pcdata " ";
	    href validator [pcdata "MarkUp Validation Service"]; pcdata "."])
       [td [validator_icon ()]])
    []

let sample tar_gz =
  html ~a:[a_xmlns `W3_org_1999_xhtml; a_xml_lang "en"]
    (head
       (title (pcdata "XHTML"))
       [style ~contenttype:"text/css" [pcdata "H1 {color: red}"]])
    (body
       ([h1 [pcdata "A sample page for the XHTML module"];
	 h2 [pcdata "Readme"];
	 p [pcdata "The following is imported "; em [pcdata "verbatim"];
	    pcdata " from the "; href "README" [pcdata "README"];
	    pcdata " file, as ca be seen in the ";
	    href "#source" [pcdata "source code of this page"];
	    pcdata " below."]] @
	List.map (fun s -> p [pcdata s]) (file_to_paragraphs "README") @
	[h2 [pcdata "Example"];
	 p [pcdata "This is a recursive example that contains its own description ";
	    entity "hellip"];
	 h2 [a ~a:[a_id "source"] [pcdata "Code"]];
	 pre [pcdata (file_to_string self)];
	 h2 [pcdata "Sources"];
	 p [pcdata "The current sources are available as a gzip compressed tar archive: ";
	    file tar_gz; pcdata ".  It includes";
	    entity "mdash"; pcdata "among others"; entity "mdash"; pcdata "the files"];
	 dl
	   (dt [file self])
	   [dd [pcdata "this example"];
	    dt [file "xML.mli"];
	    dd [pcdata "the interface XML, providing well formed documents"];
	    dt [file "xML.ml"];
	    dd [pcdata "the implementation of the XML interface"];
	    dt [file "xHTML.mli"];
	    dd [pcdata "the interface XHTML, providing documents, that are ";
		pcdata "valid according to the XHTML 1.1 DTD."];
	    dt [file "xHTML.ml"];
	    dd [pcdata "the implementation of the interface XHTML"];
	    dt [file "ChangeLog"];
	    dd [pcdata "history of changes"]];
	 hr ();
	 valid_xhtml
	   ~name:"Thorsten Ohl"
	   ~url:"http://theorie.physik.uni-wuerzburg.de/~ohl/"
	   ~email:"ohl@physik.uni-wuerzburg.de"
	   ()]))

let _ =
  let tar_gz = ref "xhtml-current.tar.gz" in
  Arg.parse [] (fun s -> tar_gz := s) "usage: homepage [archive]";
  pretty_print ~width:72 print_string (sample !tar_gz)

Sources

The current sources are available as a gzip compressed tar archive: xhtml-20050620.tar.gz. It includes—among others—the files

examples/homepage.ml
this example
xML.mli
the interface XML, providing well formed documents
xML.ml
the implementation of the XML interface
xHTML.mli
the interface XHTML, providing documents, that are valid according to the XHTML 1.1 DTD.
xHTML.ml
the implementation of the interface XHTML
ChangeLog
history of changes

This WWW page is brought to you by Thorsten Ohl <ohl@physik.uni-wuerzburg.de>. It is valid XHTML 1.1, as can be verified online by going to the W3C MarkUp Validation Service. Valid XHTML 1.1!