[erlang-questions] Record to Xml

Ulf Wiger (TN/EAB) ulf.wiger@REDACTED
Wed Jan 7 14:25:15 CET 2009


Torben Hoffmann skrev:
> 
>  You should have a look at the preprocessor function record_info/2 which 
> could give you a list of the field names like this:
> 
> FieldNames = record_info(fields,ewayRequest),
> 
> The problem is that the record name has to be known at compile time so 
> you need a function along these lines:
> 
> record_fields(#evayRequest{}) ->
>        record_info(fields,ewayRequest);
> record_fields(#other_record{}) ->
>        record_info(fields, other_record).
> 
> The downside is that you need to add a clause every time you define a 
> new record.
> The record_fields could be auto-generated using a script by keeping all 
> record definitions in a .hrl file and generate a module with the 
> record_fields function. Any scripting language will suffice here - I 
> have used both sed and Erlang for the job in the past.

You can also use the exprecs library which does exactly this,
and then some, via a parse transform.

http://forum.trapexit.org/viewtopic.php?p=21790#21790

BR,
Ulf W



More information about the erlang-questions mailing list