Erlang records to XML

classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|

Erlang records to XML

Lloyd R. Prentice-2
Hello,

Can anyone suggest a way to convert Erlang records to XML?

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

Many thanks,

LRP



_______________________________________________
erlang-questions mailing list
[hidden email]
http://erlang.org/mailman/listinfo/erlang-questions
Reply | Threaded
Open this post in threaded view
|

Re: Erlang records to XML

Hugo Mills-2
On Sat, Jun 29, 2019 at 04:41:32PM -0400, [hidden email] 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@... carfax.org.uk | uncertainty!
http://carfax.org.uk/  |                                           Vroomfondel
PGP: E2AB1DE4          |                  The Hitch-Hikers Guide to the Galaxy

_______________________________________________
erlang-questions mailing list
[hidden email]
http://erlang.org/mailman/listinfo/erlang-questions

signature.asc (853 bytes) Download Attachment
Reply | Threaded
Open this post in threaded view
|

Re: Erlang records to XML

Lloyd R. Prentice-2
In reply to this post by Lloyd R. Prentice-2
Thanks, guys!

You're the best.

Lloyd

-----Original Message-----
From: [hidden email]
Sent: Saturday, June 29, 2019 5:58pm
To: [hidden email]
Cc: "Erlang-Questions Questions" <[hidden email]>
Subject: Re: [erlang-questions] Erlang records to XML

Lloyd,

Look at the spec (not related to Dialyzer) system used by fxml_gen in ProcessOne’s fxml parser. They include an example in the main repo for XML-RPC here:
https://github.com/processone/fast_xml/blob/master/spec/README.md

They also use it for their XMPP library, if you’d like more examples. I believe it generates decoders/encoders between records and XML.

- Drew

> On Jun 29, 2019, at 4:41 PM, [hidden email] wrote:
>
> Hello,
>
> Can anyone suggest a way to convert Erlang records to XML?
>
> I can find many ways to go from XML to Erlang, but not the reverse.
>
> Many thanks,
>
> LRP
>
>
>
> _______________________________________________
> erlang-questions mailing list
> [hidden email]
> http://erlang.org/mailman/listinfo/erlang-questions


_______________________________________________
erlang-questions mailing list
[hidden email]
http://erlang.org/mailman/listinfo/erlang-questions