Basic support for XML output.
authorwenzelm
Sat, 08 Dec 2001 14:39:08 +0100
changeset 12416 9b3e7a35da30
parent 12415 74977582a585
child 12417 e5bdbcec51a3
Basic support for XML output.
src/Pure/General/xml.ML
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/Pure/General/xml.ML	Sat Dec 08 14:39:08 2001 +0100
@@ -0,0 +1,43 @@
+(*  Title:      Pure/General/xml.ML
+    ID:         $Id$
+    Author:     Markus Wenzel, LMU München
+    License:    GPL (GNU GENERAL PUBLIC LICENSE)
+
+Basic support for XML output.
+*)
+
+signature XML =
+sig
+  val element: string -> (string * string) list -> string list -> string
+  val text: string -> string
+  val header: string
+end;
+
+structure XML: XML =
+struct
+
+(* character data *)
+
+fun encode "<" = "&lt;"
+  | encode ">" = "&gt;"
+  | encode "&" = "&amp;"
+  | encode "'" = "&apos;"
+  | encode "\"" = "&quot;"
+  | encode c = c;
+
+val text = implode o map encode o explode;
+
+
+(* elements *)
+
+fun attribute (a, x) = a ^ " = " ^ quote (text x);
+
+fun element name atts cs =
+  let val elem = space_implode " " (name :: map attribute atts) in
+    if null cs then enclose "<" "/>" elem
+    else enclose "<" ">" elem ^ implode cs ^ enclose "</" ">" name
+  end;
+
+val header = "<?xml version=\"1.0\"?>\n";
+
+end;