Is there an easy way to go to the XML presentation related to the data type?
Let's say I have the following types:
Type A = | First A list of B C * string type B = B1 second A2 type C = {my_field: int; for the value SecondA (c {my_field = 10}, "just a value") I might have something like this: & lt; A Constructor = "First A" & gt; & Lt; C and gt; & Lt; My_field & gt; 10 & lt; / My_field & gt; & Lt; / C & gt; & Lt; String & gt; Just one value & lt; / String & gt; & Lt; / A & gt; Is there a library that can do something like this? Or, if I have to do it myself, what will be the best way? Note that I want to apply it to many different data types.
I know about the data types of generic programming techniques, but they are "heavy" to use in my case.
If I understand your question correctly, you can do this:
IoXML is a Camlp5 syntax extension for OCaml mli and ml files which creates XML parsers and printers for all types.
The same is true for JSON:
If you are okay using JSON, I suggest that see also This system relies on external data definition language, but it still produces idiomatic OCaml type definitions.
Update (08/15/2011): Now my own can do this, it can serial OCaml data using 4 different formats: Google Protocol Buffer, JSON, XML and Peak.
Comments
Post a Comment