xml.ml 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. let ns_rdf = "http://www.w3.org/1999/02/22-rdf-syntax-ns#"
  2. let ns_xsd = "http://www.w3.org/2001/XMLSchema#"
  3. (* and ns_sec = As2_vocab.Constants.ActivityStreams.ns_sec ^ "#" *)
  4. let ns_a = "http://www.w3.org/2005/Atom"
  5. let ns_seppo = "http://seppo.social/2023/ns#"
  6. let ns_backoffice = "http://seppo.social/2023/backoffice#"
  7. let ns_rfc7033 = "urn:ietf:rfc:7033"
  8. (* for testing purpose only *)
  9. let to_buf ?(xsl = None) ?(readme = None) ?(indent = None) (x : _ Xmlm.frag) (dst : Buffer.t) =
  10. let piw n v =
  11. (* TODO check syntax *)
  12. Printf.bprintf dst "<?%s %s?>\n" n v in
  13. piw "xml" "version=\"1.0\"";
  14. (match xsl with
  15. | Some v -> piw "xml-stylesheet" (Printf.sprintf "type='text/xsl' href='%s'" v)
  16. | None -> ());
  17. (match readme with
  18. | Some v -> Printf.bprintf dst "<!--%s-->\n" v
  19. | None -> ());
  20. let o = Xmlm.make_output ~decl:false ~indent (`Buffer dst) in
  21. Xmlm.output_doc_tree (fun x -> x) o (None,x)
  22. let pi oc n l =
  23. assert (String.contains n '"' == false);
  24. let w = output_string oc in
  25. w "<?"; w n;
  26. l |> List.fold_left
  27. (fun _ (k,v) ->
  28. assert (String.contains v '"' == false);
  29. w " "; w k; w "=\""; w v; w "\""
  30. ) ();
  31. w "?>\n"
  32. let to_chan ?(xsl = None) ?(readme = None) ?(indent = None) (x : _ Xmlm.frag) dst =
  33. pi dst "xml" ["version","1.0"];
  34. (match xsl with
  35. | Some v -> pi dst "xml-stylesheet" ["type","text/xsl"; "href",v]
  36. | None -> ());
  37. (match readme with
  38. | Some v -> Printf.fprintf dst "<!--%s-->\n" v
  39. | None -> ());
  40. let o = Xmlm.make_output ~decl:false ~indent (`Channel dst) in
  41. Xmlm.output_doc_tree (fun x -> x) o (None,x)