Introduction
Standard file content conversion supports one level of nested XML but many times we need more than one nested deep XML, We have many blogs in SCN that deals with this requirement. In this document i want to show by using standard file content conversion and message mapping.
Example Scenarios
Scenario 1
I took the example from this thread , this is flat file to two level nested XML structure.
This below is sender flat file, sender message type structure and sender file FCC parameters.
File Content Conversion
InvoiceHeader.keyFieldValue | H |
InvoiceHeader.keyFieldName | LineIndicator |
InvoiceHeader.fieldNames | LineIndicator,SupplierCode,InvoiceDate,Currency,Amount |
InvoiceHeader.fieldSeparator | ; |
InvoiceHeader.endSeparator | 'nl' |
InvoiceDetail.keyFieldName | LineIndicator |
InvoiceDetail.keyFieldValue | D |
InvoiceDetail.fieldNames | LineIndicator,LineType,CompanyCode,Costelement |
InvoiceDetail.fieldSeparator | ; |
InvoiceDetail.fieldSeparator | 'nl' |
ControlHeader.keyFieldValue | CH |
ControlHeader.keyFieldName | LineIndicator |
ControlHeader.fieldNames | ControlIndicator,TotalLine,TotalAmt |
ControlHeader.fieldSeparator | ; |
ControlHeader.endSeparator | 'nl' |
ControlData.keyFieldValue | CD |
ControlData.keyFieldName | LineIndicator |
ControlData.fieldNames | ControlIndicator,TotalLine,TotalAmt,Currency |
ControlData.fieldSeparator | ; |
ControlData.endSeparator | 'nl' |
Output
The below is output of the mapping, you can find source is flat file structure according to file above, the output is nested three level deep XML as we expected.
Mapping
The mapping simple field to field mapping except for Invoice node, ControlHeader node and ControlData, these three we just need to change the context to root node.
Scenario 2
I took this example from this thread structure not populating correctly in FCC, This example is flat structure to three level nested XML.
Input Data
The below is sender file, sender message structure and file content conversion.
File Content Conversion
FILE_HEADER.keyFieldValue | A |
FILE_HEADER.keyFieldName | KEY |
FILE_HEADER.fieldNames | KEY,FIELD1,FIELD2 |
FILE_HEADER.fieldFixedLengths | 1,2,1 |
FILE_HEADER.endSeparator | 'nl' |
VOUCHER_HEADER.keyFieldName | KEY |
VOUCHER_HEADER.keyFieldValue | B |
VOUCHER_HEADER.fieldNames | KEY,FIELD1,FIELD2 |
VOUCHER_HEADER.fieldFixedLengths | 1,2,7 |
VOUCHER_HEADER.endSeparator | 'nl' |
VOUCHER_DETAIL.keyFieldValue | D |
VOUCHER_DETAIL.keyFieldName | KEY |
VOUCHER_DETAIL.fieldNames | KEY,FIELD1,FIELD2 |
VOUCHER_DETAIL.fieldFixedLengths | 1,2,7 |
VOUCHER_DETAIL.endSeparator | 'nl' |
Output
The below is output of the mapping, you can find source is flat file structure according to file above, the output is nested three level deep XML as we expected.
Mapping
First level node you can directly map and change the context change to root node. The fields under first level node you can directly map
For all other child level nodes (Second level node and third level node) you can apply the below mapping.
For second level and third level node fields you can apply the below mapping.
User Defined Function
The below is the mapChildNode UDF which is used above, this is generic UDF we can use this in all similar requirement in future.
public void mapChildNode(int[] parentCount, int[] childCount, ResultList result, Container container) throws StreamTransformationException { int i = 0; for (; i < parentCount.length; i++) { if (childCount[i] > 0) { if (parentCount[i] > 0 && i != 0) result.addContextChange(); for (int j = 0; j < childCount[i]; j++) result.addValue(""); } else { if (i != 0) result.addContextChange(); result.addSuppress(); } } }
Similar documents in SCN
Deep XML to Flat file - using an UDF
XSLT approach - Flat File to Deep XML
DeepFCCBean - Flat File to Deep XML
Convert Flat File to Deeply XML Using Graphical Mapping
Conclusion
We can do flat file to nested deep XML using standard file content conversion and message mapping using one generic user defined function.I hope this helps.