[erlang-questions] Erlang records to XML

Hugo Mills hugo@REDACTED
Sat Jun 29 23:33:09 CEST 2019


On Sat, Jun 29, 2019 at 04:41:32PM -0400, lloyd@REDACTED wrote:
> Can anyone suggest a way to convert Erlang records to XML?

   Off the shelf, nothing I'm aware of.

> I can find many ways to go from XML to Erlang, but not the reverse.

   Well there's a bunch of different XML libraries for XML. xmerl, for
example, is a part of the standard erlang distribution, and is able to
serialise to XML. There's an example [1] in the xmerl docs. (The
others should also be able to do it, but I only checked xmerl).

   If you want a function that takes an erlang record and outputs some
kind of XML structure, then you're probably going to be disappointed.
Remember that records are mostly a funny compile-time syntax for
tuples, and that the names are (mostly) lost at runtime. You're going
to have to build the internal data structures that your chosen XML
library uses, then serialise from those.

   Alternatively, if you don't want to be able to read the XML you're
writing, and it's not a massively complicated structure, it's usually
fairly simple to just build the XML directly.

   Hugo.

[1] http://erlang.org/doc/apps/xmerl/xmerl_ug.html#example--create-xml-out-of-arbitrary-data

-- 
Hugo Mills             | We demand rigidly defined areas of doubt and
hugo@REDACTED carfax.org.uk | uncertainty!
http://carfax.org.uk/  |                                           Vroomfondel
PGP: E2AB1DE4          |                  The Hitch-Hikers Guide to the Galaxy
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 836 bytes
Desc: Digital signature
URL: <http://erlang.org/pipermail/erlang-questions/attachments/20190629/e272957d/attachment.bin>


More information about the erlang-questions mailing list