Sidebar

How to synchronize processing of multiple XML files

0 votes
490 views
asked Mar 31, 2015 by (220 points)
I need to process two XML files. Both files are it the same folder.

In the Source Node I have code which loops through all existing XML files

In the folder and adds a new inbound message:

 

for ( var i = 0; i< allFiles; i++ )

{

            …..

            ….

            …..

            qie.addInboundMessage( qie.reqdFile; file.getName() );

            qie.deletFile( file );

}

 

In Condition Node I check the name of the file and continue with Mapping Node associated with that file.

Destination Node writes file to other location.

 

Everything works file for each file separately.  

When I have both files together the first file gets ignored. The second file works but

creates some exception related to first file.

 

It looks like the entire process should be synchronized for each XML file.

 

Thanks in advance for any help.

 

Michael
commented Apr 10, 2015 by rich-c-2789 (16,180 points)
What logic is used in the condition node?

1 Answer

0 votes

One solution might be to have both files part of the same message.  You could do this by loading the xml contents in to a JSON object.  You could probably do the same by loading both files into a single XML message, but I find JSON to be cleaner since you don't have to deal with the prolog nested in the XML.

var bothFiles = {};

bothFiles.firstFile = '' + firstFileContents;

bothFiles.secondFile = '' + secondFileContents;

qie.addInboundMessage(JSON.stringify(bothFiles), fileName);

Then within your mappings, you have access to both files in a synchronous way:

var jsonMessage = JSON.parse(message.getNode('/'));

var firstXml = qie.parseXmlString(jsonMessage.firstFile);

var secondXml = qie.parseXmlString(jsonMessage.secondFile);

As you branch using your condition node, you can change the message type to xml and set it to which file you need to write.  You can route to two mapping nodes... one sets first as the message, the other sets the second as the message:

var jsonMessage = JSON.parse(message.getNode('/'));

message = qie.createXmlMessage(jsonMessage.firstFile); // for the firstFile

answered May 7, 2015 by mike-r-7535 (13,830 points)
...