So I am using Erlsom to parse a XML file that also has a matching XSD file. Erlsome includes an option to generate records (.erl file) based on the model of the XSD (erlsom:write_xsd_hrl_file).
This auto-generated .erl file includes records that start with an uppercased letter. For example:
-record('Pip3A4PurchaseOrderRequestType', {anyAttribs :: anyAttribs(),
fromRole :: roleType(),
'Authentication' :: 'AuthenticationType'(),
'GlobalDocumentFunctionCode' :: string(),
'PurchaseOrder' :: 'PurchaseOrderType'(),
thisDocumentGenerationDateTime :: 'DateTimeType'(),
thisDocumentIdentifier :: 'ProprietaryDocumentIdentifierType'(),
toRole :: roleType()}).
So when I use a record in my elixir module (like the one below) I can’t use it.
Record.defrecord :Pip3A4PurchaseOrderRequestType, Record.extract(:Pip3A4PurchaseOrderRequestType, from: @hrl)
Erlang/OTP 19 [erts-8.3] [source] [64-bit] [smp:8:8] [async-threads:10] [hipe] [kernel-poll:false] [dtrace]
Interactive Elixir (1.4.2) - press Ctrl+C to exit (type h() ENTER for help)
iex(1)> require Ot.Poc
Ot.Poc
iex(2)> record = Ot.Poc.Pip3A4PurchaseOrderRequestType()
** (SyntaxError) iex:2: syntax error before: '('
iex(2)> record = Ot.Poc.pip3A4PurchaseOrderRequestType()
** (UndefinedFunctionError) function Ot.Poc.pip3A4PurchaseOrderRequestType/0 is undefined or private. Did you mean one of:
* Pip3A4PurchaseOrderRequestType/0
* Pip3A4PurchaseOrderRequestType/1
* Pip3A4PurchaseOrderRequestType/2
(ot) Ot.Poc.pip3A4PurchaseOrderRequestType()
I thought I could fix this by defining the record as fallowed:
# v--- lower cased p v--- Upper cased p
Record.defrecord :pip3A4PurchaseOrderRequestType, Record.extract(:Pip3A4PurchaseOrderRequestType, from: @hrl)
Now I can call Ot.Poc.pip3A4PurchaseOrderRequestType()
, but when I try to pass the record data it fails because the record links to other records that are starting with upper cased names, but first it fails because it can’t match it self with the data:
** (ArgumentError) expected argument to be a literal atom, literal keyword or a :pip3A4PurchaseOrderRequestType record, got runtime: {:Pip3A4PurchaseOrderRequestType, [], {:roleType, [],
So at this point I tried everything I could think off without success. What can I do without having to adjust the .erl file manually (392 LoC)?