cancel
Showing results for 
Search instead for 
Did you mean: 

Can we combine multiple XMLs into single xml using append option in receiver channel in SAP PI 7.4

krishnavamsikola
Explorer
0 Kudos
1,361

Is it possible to create a Pass through scenario where sender channel picks multiple XMLs of different structure from a directory and combine using append command in receiver channel to form single xml and place in target path

Accepted Solutions (1)

Accepted Solutions (1)

anupam_ghosh2
Active Contributor
0 Kudos

hi krishnavamsikola,

Split scenarios into two ICO.

First will be file to file with in append mode on receiver side. After sender channel stops for first ICO, then task of second ICO begins. The second ICO needs java mapping or adapter module to read the merged file produced from first scenario. Then reformats the file to create valid xml. Let me illustrate with example

These are 3 different xml files

<note>
<to>Tove</to>
<from>Jani</from>
<heading>Reminder</heading>
<body>Don't forget me this weekend!</body>
</note>
<note>
<to>Tove1</to>
<from>Jani1</from>
<heading>Reminder1</heading>
<body>hi</body>
</note>
<note>
<to>Tove2</to>
<from>Jani2</from>
<heading>Reminder2</heading>
<body>hello</body>
</note>

after first ICO merges this file it will become like this

<note>
<to>Tove</to>
<from>Jani</from>
<heading>Reminder</heading>
<body>Don't forget me this weekend!</body>
</note>
<note>
<to>Tove1</to>
<from>Jani1</from>
<heading>Reminder1</heading>
<body>hi</body>
</note>
<note>
<to>Tove2</to>
<from>Jani2</from>
<heading>Reminder2</heading>
<body>hello</body>
</note>

which is not valid xml.

In second ICO your java mapping/adapter module converts it into valid xml as shown below by adding a root node called "Email". The way you want to convert it into valid XML depends on your project requirement.

<Email>
<note>
<to>Tove</to>
<from>Jani</from>
<heading>Reminder</heading>
<body>Don't forget me this weekend!</body>
</note>
<note>
<to>Tove1</to>
<from>Jani1</from>
<heading>Reminder1</heading>
<body>hi</body>
</note>
<note>
<to>Tove2</to>
<from>Jani2</from>
<heading>Reminder2</heading>
<body>hello</body>
</note>
</Email>

You can consult this java code for further details on merging of XML.

This logic needs to be present in your mapping/module.

Regards

Anupam

Answers (3)

Answers (3)

anupam_ghosh2
Active Contributor
0 Kudos

hi krishnavamsikola,

The requirement is not clear.

You have not clarified on how PI server will understand when to stop appending of the incoming files.

If this information is not available or not clear, I am afraid this is not possible in PI.

Regards

Anupam

krishnavamsikola
Explorer
0 Kudos

we can schedule the channels to start at a particular time and fetch all the files in the path.

peter_wallner2
Active Contributor
0 Kudos

Hello,

look at this: https://blogs.sap.com/2014/06/06/merge-multiple-files-without-bpm/

I followed that blog a few months ago and it works well. The only downside: the actual sender channel that does the combining must be of NFS. So I am pulling 2 files from an SFTP and save them on a folder on our PO system. The next scenario then picks the files from there with an NFS (File) Sender channel and the OM has the java map as the first mapping step and combines the two XMLs.

Good luck, Peter

krishnavamsikola
Explorer
0 Kudos

Hi Peter, firstly thanks for the suggestion, can we use this technique to merge more than 2 files.

peter_wallner2
Active Contributor
0 Kudos

Hello Vamsi, I don't know. I only tried it with 2 files, like it is done in the blog. I would give it a try.

0 Kudos

Hi Peter, I’m following that blog from Arpil for the same requirement but i’m getting a NullPointerException; while trying to invoke the method org.w3c.dom.Node.getNodeType() of a null object loaded from local variable source. Can you let me know how your files look like? The channel was able to pick up the file and the attachments.

peter_wallner2
Active Contributor
0 Kudos

Hello Gal Leeloo,

there is one line in the java mapping:

Element element = (Element) attachmentDoc.getElementsByTagName("Recordset2").item(0);

that basically "grabs" the attachment XML by using the root elment name. In my example that root is called "Recordset2". Make sure you adapt that in the java map to that element name. If not, I could imaging you get a null pointer because it tries to get an element by tag name and does not find any.

stefan_grube
Active Contributor
0 Kudos

In principle yes, but if you append different XML files to a single file, then the result would not be a valid XML file.