我需要将下面的MT txt文件(MT 760的示例)转换为MT XML格式。我正在使用SWIFT SDK MT2XML类进行转换。以下是示例输入文件,并引用了2018年的相应架构,即fin.760.2018.xsd
SampleMT760.txt(包含虚拟数据)
{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:用于翻译的代码段
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);
}
当我尝试执行TranslationSvc时,我收到以下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)
有人可以建议输入文件的格式正确吗?如果有人可以向我提供示例工作输入文件,那就好了。
答案 0 :(得分:0)
您的示例消息不正确。块2中的消息类型是MT011,它是系统消息,而不是您期望的MT760。
入站MT760的第2块应类似于:
{2:O 760 1155081106BBBBUS00DGST08298565620811060655N}
您可以在日期,时间和BIC代码中放入虚拟数据,但必须保留消息类型。
入站消息中应用程序头(块2)的结构如下:
您可以在https://www.prowidesoftware.com/resources/SWIFT上找到更多信息。 顺便说一下,我是开源库Prowide Core的作者之一,该库包括MT到XML的转换。它与SWIFT SDK使用的XML不同,而是Prowide的专有。关键区别在于,SWIFT SDK XML转换至少在结构上要求输入消息有效,而Prowide Core XML可以来回转换任何有效或无效的MT。
PD:完整的MT760样品
{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]
-}
[CRLF]是回车符和换行符