简体   繁体   中英

SWIFT MT txt to MT XML conversion

I need to convert the below MT txt file (sample of MT 760) to MT XML format. I am using SWIFT SDK MT2XML class to convert. Below is the sample input file and referring to corresponding schema for the year 2018 ie fin.760.2018.xsd

SampleMT760.txt (It contains dummy data)

{1:F01AAAAAAAAAAAI1111111111}
{2:O111111111111XXXXXXXXXXXX111111111111111111111N}
{3:{108:T1A11111111111A111}}
{4:
:27:1/1
:20:123456123456ABCD
:23:ISSUE
:30:180813
:40C:URDG
:77C:SOME MESSAGE
:72:/PHONBEN/
-}
{5:{CHK:}{TNG:}}{S:{SAC:}{COP:P}{MAN:A2A11}}

TranslationSvc.java: Code snippet for translation

public static void translate(String inputData) throws Exception { 

        // parse the XML schema for the entire MT message (block 1 to 5)
        final DocumentBuilderFactory builderFactory = DocumentBuilderFactory.newInstance();
        builderFactory.setNamespaceAware(true);
        final DocumentBuilder builder = builderFactory.newDocumentBuilder();
        final Document schema = builder.parse(new File(SCHEMA_FILE)); 

        // create a ISchemaDocResolver which loads the correct schema by filename
        ISchemaDocResolver resolver = new ISchemaDocResolver() {
            public SchemaDoc resolveSchemaDoc(final String pNamespaceURI) {
                // the namespace which is passed here it the namespace of the
                // block 4 content
                if (pNamespaceURI.endsWith("fin.760.2018")) {
                    DocumentBuilder builder = null;
                    try {
                        builder = builderFactory.newDocumentBuilder();
                    } catch (ParserConfigurationException e) {
                        e.printStackTrace();
                    }
                    Document schema = null;
                    try {
                        schema = builder.parse(new File(SCHEMA_FILE));
                    } catch (SAXException | IOException e) {
                        e.printStackTrace();
                    }
                    return new SchemaDoc(schema);
                }
                return null;
            }
        };

            final SchemaDoc schemaDoc = new SchemaDoc(schema, resolver);
            final MT2Xml mt2xml = new MT2Xml(schemaDoc);

        // convert an entire MT message (block 1 to 5) to its corresponding XML format
        final Document result = builder.newDocument();
        mt2xml.convert(inputData, result);
    }

When I try to execute TranslationSvc, I am receiving the below ConversionError:

Exception in thread "main" com.swift.converter.ErrorReportException: <ErrorReport>
<ConversionErrors>
<Error>
<Code>
TC00100
</Code>
<Message>
Unexpected field 1
</Message>
<Location>
<LineNumber>
0
</LineNumber>
</Location>
</Error>
</ConversionErrors>
</ErrorReport>

    at com.swift.converter.ReportErrorHandler.checkEnd(ReportErrorHandler.java:205)
    at com.swift.converter.MT2Xml.convert(MT2Xml.java:164)
    at com.swift.converter.MT2Xml.convert(MT2Xml.java:189)
    at TranslationSvc.translation(TranslationSvc.java:95)
    at TranslationSvc.main(TranslationSvc.java:47)

Can someone please suggest if the input file is in the correct format? If would be great if someone can provide me with the sample working input file.

your sample message is incorrect. The message type in block 2 refers to an MT011, which is a system message and not the MT760 you expect.

Block 2 for an inbound MT760 should be like:

{2:O 760 1155081106BBBBUS00DGST08298565620811060655N}

You can put dummy data in the date, time and BIC code, but you must preserve the message type.

The structure for the application header (block 2) in a inbound message is as follows:

  • O = Output
  • Message type
  • Input time with respect to the sender
  • The Message Input Reference (MIR), including the input date, with Sender's address.
  • Output date and time with respect to Receiver
  • Message priority

You can find more information at https://www.prowidesoftware.com/resources/SWIFT And by the way, I'm one of the authors of the open source library Prowide Core, which includes MT to XML conversion. It is not the same XML used by the SWIFT SDK, but a proprietary from Prowide. The key difference is that the SWIFT SDK XML conversion requires the input message to be valid at least in terms of structure, while the Prowide Core XML can convert back and forth any MT, valid or invalid.

PD: Full MT760 sample

{1:F01NWBKGB2LD36A6294534377}{2:O7601155081106BBBBUS00DGST08298565620811060655N}{4: [CRLF]
:27:1/1 [CRLF]
:20:123456123456ABCD [CRLF]
:23:ISSUE [CRLF]
:30:180813 [CRLF]
:40C:URDG [CRLF]
:77C:SOME MESSAGE [CRLF]
SECOND LINE [CRLF]
-}

Where [CRLF] is carriage return and line feed

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM