S A - 2011-08-10

Greetings !  I am trying to convert Records which are in a bit of a proprietary layout. Each record contains a header on a new line followed by a comment line (all ---). Following the header (and comment line) is a series of fields of the type " number : fieldname = value". Each record is separated from the next using a blank line.

The complexity here is each record can optionally have one or more sub-record identified as:
" number : SUBRECORD.id(instance)::FIELD.fieldname - value"
These are usually at the end of record field definitions. See example with two records below : (#00001 has SUBRECORDs, whilst #00002 doesn't.

RECORDTYPE=ASC [length:483] (R:00001)
-------------------------------------------------------
 001 :  UnixTimeStamp = 1312723397
 002 :  OriginatingNetwork = RICHMOND
 003 :  Filename = testdata.dat
 004 :  OriginatingNumber = 9999687045
 005 :  TerminatingNumber = 007654687313
 006 :  RecordID = 0625
 007 :  LayoutId = ASC
 008 :  Date = 20110801
 009 :  Time = 103700
 010 :  StartTimeStamp = 20110801103700
 011 :  StartTime = 1312207200
 012 :  Checksum = 0x5DD605C8D56BAD897592B67CEDE47FB5
 013 :  SUBRECORD.720(1)::FIELD.T88 = 0x720C
 014 :  SUBRECORD.720(1)::FIELD.T730 = 0x001C
 015 :  SUBRECORD.720(1)::FIELD.T731 = 0x03175170000C
 016 :  SUBRECORD.720(1)::FIELD.T732 = 0xFFFFFFFFFF
 017 :  SUBRECORD.720(1)::FIELD.T733 = 0xFFFFFFFFFFFFFFFF
 018 :  SUBRECORD.720(1)::FIELD.T734 = 0x3090000C
 018 :  SUBRECORD.0(1)::FIELD.T88 = 0x000C
RECORDTYPE=ASC [length:483] (R:00002)
-------------------------------------------------------
 001 :  UnixTimeStamp = 1312723398
 002 :  OriginatingNetwork = RICHMOND
 003 :  Filename = testdata.dat
 004 :  OriginatingNumber = 8007551212
 005 :  TerminatingNumber = 044897242991
 006 :  RecordID = 0625
 007 :  LayoutId = ASC
 008 :  Date = 20110801
 009 :  Time = 103700
 010 :  StartTimeStamp = 20110801103700
 011 :  StartTime = 1312207200
 012 :  Checksum = 0x5DD605C8D56BAD897592B67CEDE47FB5

The expected output is as follows:

<Records>
    <Record length="483" id="00001">
      <Fields>
        <UnixTimeStamp>1312723397</UnixTimeStamp>
        <OriginatingNetwork>RICHMOND</OriginatingNetwork>
        ....
        <Checksum>0x5DD605C8D56BAD897592B67CEDE47FB5</Checksum>
      <Fields>
        <SUBRECORD id="720" instance="1">
            <Fields>
                <FIELD.T88>0x720C</FIELD.T88>
                <FIELD.T730>0x001C</FIELD.T730>
                ...
            </Fields>
        </SUBRECORD>
        <SUBRECORD id="0" instance="1">
            <Fields>
                <FIELD.T88>0x000C</FIELD.T88>
            </Fields>
        </SUBRECORD>
    </Record>

    <Record length="413" id="00002">
      <Fields>
        <UnixTimeStamp>1312723398</UnixTimeStamp>
        <OriginatingNetwork>RICHMOND</OriginatingNetwork>
        ....
        <Checksum>0x5DD605C8D56BAD897592B67CEDE47FB5</Checksum>
      <Fields>
    </Record>

</Records>

Can you provide a guideline on how I can set up the configuration to parse this kind of layout ? I have looked at the examples and tried quite a few settings looking at them, but I am getting nowhere close to generating the desired output.

Thank you in advance.