Ich möchte eine Ausgabe mit Boxen und XML in Format module drucken. Eine Idee Format ist wie folgt:Boxen und XML im Format Modul
<Events>
<Event>
<name> haha </name>
<name> haha </name>
</Event>
<Event>
<name> lili </name>
<name> lili </name>
</Event>
<Event>
<name> lolo </name>
<name> lolo </name>
</Event>
</Events>
Im Moment ist mein Code wie folgt, es nicht genau drucken, was ich erwarte, dass (Ich lasse hier das falsche Ergebnis setzen).
(* in event.ml *)
let print_name (fmt: formatter) (x: t) : unit =
Format.open_tag "Name";
Format.fprintf fmt "%s" (get_name x);
Format.close_tag()
(* in events.ml *)
let print (fmt: formatter) (x: t) : unit =
let print (fmt: formatter) (x: t) : unit =
List.iter
(fun m ->
Format.open_tag "Event";
Format.fprintf fmt "@,@[<v 4>%[email protected],%[email protected]," Event.print_name m
Event.print_name m; (* print twice *)
Format.close_tag();
Format.fprintf fmt "@,@]")
x
in
Format.open_tag "Events";
Format.fprintf fmt "@,@[<v 4>%[email protected]]@," print x;
Format.close_tag()
(* in main.ml *)
Format.fprintf Format.std_formatter "%a" Events.print x
Ich bin mir nicht sicher, ob ich die Box gut verstehe, besonders wenn es sich um XML handelt. Weiß jemand, wie man diese Formate richtig schreibt?