ppx_protocol_conv — works, but the list is always serialized to l tag and the record is always serialized to record; I can change names only for record fields;
ezxmlm — I failed to find how to make a tag with a custom namespace;
xmlm — too complicated for my simple task.
It cannot be this hard, I must be doing something wrong.
What is the standard way to create simple XML data?
Can you specify a sample data type that looks like the type you want to encode, and how you want the fields to be encoded? Since there are different valid ways of encoding eg a record type to XML, like
type person = { id : int; name : string }
Could be encoded as
<person>
<id>1</id>
<name>Bob</name>
</person>
Or as
<person id="1" name="Bob"/>
EDIT: let me also mention that my library pure-html allows creating and rendering XML data. Eg for the above type, I could encode it both ways shown:
open Pure_html
let encoding1 =
let person = std_tag "person"
and id = std_tag "id"
and name = std_tag "name" in
fun { id = i; name = n } ->
person [] [
id [] [txt "%d" i];
name [] [txt "%s" n];
]
let encoding2 =
let person = std_tag "person"
and id = int_attr "id"
and name = string_attr "name" in
fun { id = i; name = n } ->
person [id i; name "%s" n] []
No prob. Just to clarify, you can easily use namespaces: let answers = std_tag "myns:answers". And you can also easily wrap the answers in the myns:answers tag, eg:
module Myns = struct
let answers = std_tag "myns:answers"
let answer = ...
...
end
let answer_node { resource; state } =
Myns.answer [] [
Myns.resource "%s" resource;
Myns.state "%s" state;
]
let answers_node answers =
Myns.answers [] (List.map answer_node answers)