0

我有一个 MT940 消息的数据集

C 180731 斯里兰卡卢比 50000,00

我希望它与 XSD 一样显示。有人可以帮我处理 XSD。

C180731LKR50000,00

4

1 回答 1

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>.

于 2019-06-25T12:03:45.377 回答