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