Atdgen for XML?

I’m currently working on a project for read XLSX documents and I’m finding that the majority of the code is for parsing XML into records (for example, everything in this folder). If this was JSON, I’d use atdgen, but it doesn’t seem to support XML. Is there some sort of code-generation tool for XML?

Atdgen doesn’t handle XML. It could be extended to do so, but that would require a bit of work, especially since XML is richer than json.

In the old days there was IoXML, which was based on camlp4 and would generate serialization functions from type definitions. As far as I remember, it lacked a mechanism to specify how to customize your mapping from OCaml to XML, so it was good for dumping your own data but not so much for reading data from external sources.

Edit: IoXML’s last release is from 2016 and works with camlp5, so it might just work for you. Or you could tweak it to accommodate XLSX idioms.

You could try ppx_protocol_conv which comes with a deriving plugin similar to yojson but using xml-light.

Looks potentially useful. I’ll have to play around with it tonight to see if I can make it do what I want (I’m a little suspicious of a library that serializes XML and JSON without needing extra info for the XML to tell it what should be elements or attributes, but maybe what I want is there and just not in the README).