Skip to Content
Author's profile photo Praveen Gandepalli

Flat File to DeepXML using Standard FCC and Message Mapping Part 1

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 Re: Sender File content conversion , 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_FCC.png

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.

InvoiceOutput.jpg

Mapping

The mapping simple field to field mapping except for ControlHeader node and ControlData node, these two we just need to change the context to root node.

ControlHeaderMap.jpgControlDataMap.jpg

invoiceMap.jpg

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_FCC.png

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.

MappingInputOutput.png

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

FileHeaderMap.png

For all other child level nodes (Second level node and third level node) you can apply the below mapping.

SecondLevelMap.png

For second level and third level node fields you can apply the below mapping.

FieldsUnderSecond.png

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.

UDF.png


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

Flat file to deep XML – 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.

Assigned Tags

      2 Comments
      You must be Logged on to comment or reply to a post.
      Author's profile photo Maheswarareddy Konda
      Maheswarareddy Konda

      Hi Praveen,

      thanks for blog !!

      Blog explained very well, though i am guessing your logic(config for sender channel) working depending on first first node(here Invoice header)

      where ever that Invoice Header comes and then changing the context for root node(here Invoce).

      my doubt is , in case record(Invoice) comes without Invoce Header node then is that your config could produce different record or added in previous records?

      Author's profile photo Praveen Gandepalli
      Praveen Gandepalli
      Blog Post Author

      Hi Maheswarareddy,

      If InvoiceHeader missing in the file those InvoiceDetail rows will be part of previous InvoiceHeader except first InvoiceHeader missing in the file, Anyway i updated the blog.

      Regards,

      Praveen.