使用DFDL在一行中解析输入

时间:2019-06-25 10:21:28

标签: xml xsd dfdl

我有一个MT940消息的数据集

C 180731 LKR 50000,00

我希望它与XSD一起显示。有人可以帮我XSD。

C180731LKR50000,00

1 个答案:

答案 0 :(得分:0)

以下各项通过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>

解析示例数据将产生以下XML:

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

请注意,该数量没有小数,因为小数部分是00,并且Daffodil输出规范化的数字。如果该金额类似于“ 50000,99”,它将输出为<Amount>50000.99</Amount>