[erlang-questions] Record to Xml

Torben Hoffmann torben.lehoff@REDACTED
Wed Jan 7 14:59:34 CET 2009

On Wed, Jan 7, 2009 at 2:25 PM, Ulf Wiger (TN/EAB)

> 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

Bummer - I should have googled this a lot better before I wrote my own code.

Thanks for the tip,
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://erlang.org/pipermail/erlang-questions/attachments/20090107/8b9f76df/attachment.htm>

More information about the erlang-questions mailing list