Seppo.Social -> Seppo.mro.name
[Seppo.git] / lib / xml.ml
blob90460fbe0ca9f73168c841c89e606d1cec32d728
2 open Astring
4 let ns_rdf = "http://www.w3.org/1999/02/22-rdf-syntax-ns#"
5 let ns_xsd = "http://www.w3.org/2001/XMLSchema"
6 (* and ns_sec = As2_vocab.Constants.ActivityStreams.ns_sec ^ "#" *)
7 let ns_a = "http://www.w3.org/2005/Atom" (* https://www.rfc-editor.org/rfc/rfc4287#section-2 *)
8 let ns_thr = "http://purl.org/syndication/thread/1.0" (* https://www.rfc-editor.org/rfc/rfc4685#section-2 *)
9 let ns_seppo = "http://seppo.mro.name/2023/ns#"
10 let ns_backoffice = "http://seppo.mro.name/2023/backoffice#"
11 let ns_rfc7033 = "urn:ietf:rfc:7033"
12 let ns_rfc7565 = "urn:ietf:rfc:7565"
13 let ns_as = As2_vocab.Constants.ActivityStreams.ns_as
14 let ns_xhtml = "http://www.w3.org/1999/xhtml"
16 (* for testing purpose only *)
17 let to_buf ?(xsl = None) ?(readme = None) ?(indent = None) (x : _ Xmlm.frag) (dst : Buffer.t) =
18 let piw n v =
19 (* TODO check syntax *)
20 Printf.bprintf dst "<?%s %s?>\n" n v in
21 piw "xml" "version=\"1.0\"";
22 (match xsl with
23 | Some v -> piw "xml-stylesheet" (Printf.sprintf "type='text/xsl' href='%s'" v)
24 | None -> ());
25 (match readme with
26 | Some v -> Printf.bprintf dst "<!--%s-->\n" v
27 | None -> ());
28 let o = Xmlm.make_output ~decl:false ~indent (`Buffer dst) in
29 Xmlm.output_doc_tree (fun x -> x) o (None,x)
31 let pi oc n l =
32 assert (String.exists (fun c -> c == '"') n == false);
33 let w = output_string oc in
34 w "<?"; w n;
35 l |> List.fold_left
36 (fun _ (k,v) ->
37 assert (String.exists (fun c -> c == '"') v == false);
38 w " "; w k; w "=\""; w v; w "\""
39 ) ();
40 w "?>\n"
42 let to_chan ?(xsl = None) ?(readme = None) ?(indent = None) (x : _ Xmlm.frag) dst =
43 pi dst "xml" ["version","1.0"];
44 (match xsl with
45 | Some v -> pi dst "xml-stylesheet" ["type","text/xsl"; "href",v]
46 | None -> ());
47 (match readme with
48 | Some v -> Printf.fprintf dst "<!--%s-->\n" v
49 | None -> ());
50 let o = Xmlm.make_output ~decl:false ~indent (`Channel dst) in
51 Xmlm.output_doc_tree (fun x -> x) o (None,x)