MessageObjects Tutorial: XML to SWIFT
III. XML to Swift
Step 1: Creating XML for Transformation to SWIFT
In the first part of this tutorial, you learned how
to transform SWIFT to XML. Once you have an XML representation
of a SWIFT message, you can convert it to a SWIFT message.
If you have performed step
1 of part II, then you can now click button "GO"
- this will place a call to sx.xml2swiftAsString().
You should see the result here.
If your initial SWIFT message was correctly formed,
you should usually get the same message when converting
to XML and back to SWIFT.
There may be differences when using ISO15022 message
types, because, most unfortunately, SWIFT does not enforce
the sequence of generic tags/qualifiers in repetitive
fields.
MessageObjects reorganises the sequence into the recommended
sequence in order to be able to validate mandatory occurrences
correctly.
When converting back to SWIFT you may see that some
fields have been rearranged.
Of course, in real life you will not be converting from SWIFT to XML and back again (unless you are simply replacing a value).
Step 2: Creating an empty XML Message
You can create an empty XML message from scratch by
using sx.setMsgType("200"). Click
"GO" to do that now.
Now you must fill at least the mandatory fields of the header and message body. Go to the next step to do that.
Step 3: Node Values
Follow the previous step, so that you have an empty
XML representation of an MT200 loaded into the API.
The easiest way to fill the fields is by using setNodeValue:
Click "GO" to set the values.
Please note how MessageObjects added brackets and slashes for you and converted the decimal point to a comma.
The Key attribute is used for setting node values,
because it is the only single unique reference available.
As remarked under II.5
the Key attribute may change when there is a standards
change.
A way of ensuring that your code stays valid, is to
generate data entry forms "on the fly" from
XML.
You can set the HTML input element's name to the Key
attribute's value and after Submit use the name and
value of the input element to pass to setNodeValue.
In a VB application you can generate a control collection
and use the "Tag" property to store the Key
attribute value.
You could also create a nodelist as described in II.5
and only treat the nodes whose Tag, SubField, etc. attributes
match your requirements by extracting their Key attribute.
Step 4: Iterations and Rows
In the previous step we created a simple MT200, which
has practically no hierarchical depth.
If we now look at an MT502, we will see more hierarchy:
we have sequences, iterations and rows.
As long as we do not need to add a new row the same
approach as for the MT200 is valid.
Follow the previous steps but load an MT502, so that
you have an empty XML representation of an MT502 loaded
into the API.
The easiest way to fill the fields is by using setNodeValue:
sx.setNodeValue("LTId1","ANASCH22AXXX")
sx.setNodeValue("LTId2","ANASCH22XXXX")
sx.setNodeValue("priodelmon","N")
sx.setNodeValue("AA_SA_2_20C_2","TREF")
sx.setNodeValue("AA_SA_3_23G_1","NEWM")
sx.setNodeValue("AA_SA_L1_1_22F_3","TRAD")
Now add a row to the iteration "Linkages", so that there are 2 rows:
sx.AddRow("AA_SA_SA1_1")
'fill row 1:
sx.setNodeValue("AA_SA_SA1_I1_R1_4_20C_1","PREV")
sx.setNodeValue("AA_SA_SA1_I1_R1_4_20C_2","prevref")
'fill row 2:
sx.setNodeValue("AA_SA_SA1_I1_R2_4_20C_1","RELA")
sx.setNodeValue("AA_SA_SA1_I1_R2_4_20C_2","relatedref")
Click "GO" to set the values. Please note how MessageObjects added brackets and slashes for you as well as fields 16R/16S.
