user2990519
user2990519

Reputation: 11

Parsing input with with DFDL in one line

I have a data set of MT940 message

C 180731 LKR 50000,00

I want this to displayed as with a XSD. Can someone help me with XSD.

C180731LKR50000,00

Upvotes: 0

Views: 285

Answers (1)

stevedlawrence
stevedlawrence

Reputation: 480

The following is tested with Apache Daffodil 2.3.0:

<xs:schema
  xmlns:xs="http://www.w3.org/2001/XMLSchema"
  xmlns:dfdl="http://www.ogf.org/dfdl/dfdl-1.0/">

  <xs:include schemaLocation="org/apache/daffodil/xsd/DFDLGeneralFormat.dfdl.xsd" />

  <xs:annotation>
    <xs:appinfo source="http://www.ogf.org/dfdl/">
      <dfdl:format ref="GeneralFormat"
        representation="text" />
    </xs:appinfo>
  </xs:annotation>

  <xs:element name="MT940">
    <xs:complexType>
      <xs:sequence>
        <xs:element name="CreditDebitIndicator" type="xs:string"
          dfdl:lengthKind="explicit" dfdl:length="1" />
        <xs:element name="Date" type="xs:date"
          dfdl:lengthKind="explicit" dfdl:length="6"
          dfdl:calendarPatternKind="explicit" dfdl:calendarPattern="yyMMdd" />
        <xs:element name="Currency" type="xs:string"
          dfdl:lengthKind="explicit" dfdl:length="3" />
        <xs:element name="Amount" type="xs:decimal"
          dfdl:lengthKind="delimited" dfdl:textNumberCheckPolicy="strict"
          dfdl:textNumberPattern="#0.00"
          dfdl:textStandardDecimalSeparator=","
          dfdl:textStandardGroupingSeparator="." />
      </xs:sequence>
    </xs:complexType>
  </xs:element>

</xs:schema>

Parsing your example data results in the following XML:

<MT940>
  <CreditDebitIndicator>C</CreditDebitIndicator>
  <Date>2018-07-31</Date>
  <Currency>LKR</Currency>
  <Amount>50000</Amount>
</MT940>

Note that the amount does not have any decimals because the fraction part was 00 and Daffodil outputs canonicalized numbers. If the amount was something like "50000,99" instead, it would output as <Amount>50000.99</Amount>.

Upvotes: 0

Related Questions