How to convert Ocaml data type to xml and vice versa?

Is there an easy way to go from the Ocaml data type to the corresponding xml view?

Suppose I have the following types:

type A =
  | FirstA of B list
  | SecondA of C * string

type B = B1 | B2

type C = {
  my_field: int;
}

For value, SecondA (C {my_field=10}, "just a value")I would like to get maybe something like this:

<A constructor="FirstA">
   <C><my_field>10</my_field></C>
   <string>just a value</string>
</A>

Is there a library that can do something like this? Or, if I need to do this myself, what would be the best approach? Note that I want to apply this to several different data types.

I am familiar with general data type programming methods, but they are too "heavy" to use in my case.

+5
source share
2 answers

, IoXML, :

IoXML - Camlp5 OCaml mli ml, XML- .

JSON : https://github.com/mirage/shelf

JSON, ATD/yojson. , OCaml.

UPDATE (08/15/2011): Piqi . OCaml, 4 : Google, JSON, XML Piq.

+6

All Articles