Structural split

Structural split

This article covers the advanced, converter workflow component, Structural split. This component should normally be used instead of the Split XML component as the structural split normally generates the wanted output. 

The component can be used if you want to split up a large XML file with multiple documents inside into multiple XML files, that each contains only a single document e.g. if you want to create a PDF file for each document.

The structural split keeps the common header and the XML structure for each of the splitted XML files is the same as for the initial XML file. This is normally better than the split XML component, where the common header is not included in each output and the root of the output files is the node referenced to for the split.

The main setting of the structural split is the Split XPath node. For each node, that match this path the rest of the workflow (connected to the right of the component) will be executed - similar to a repeat loop.

The component has these parameters:

Split XPath
This refers to the node, that should be used as the basis for the split. Each node found will result in a new XML output, which is stored in the payload. If the node is not found, then no output will be generated.
The easiest way to setup this path is to load a sample XML file in the workflow and in this component simply click the magnifying glass and then double click on the node, that you want to refer to.

In the example above the demo xml file, Demo_Invoice.xml was used and the path refers to the detail lines. With this setup a new XML output is created for each detail line in the input file.

Collect attachments
This option can be used if you want one attachment in an output email for each document found in the input XML file. For that you might use both the component, Set attachment name and Payload to attachment for each of the splitted XML files. In order to force the workflow to remember and collect all of these attachments you need to enable this function on the Structural split component. If you do not enable this, then each "repeat loop" starts with an empty list of attachments.

In order to use the all collected attachments e.g. for attachments in an outgoing email, then you could consider to insert this structural split into a choice and join component with a dummy condition, that is always true. 

Example

Below is an example where we will split up the Demo_invoice.xml file - per detail line and create an email which contains multiple PDF files with just a single detail line in each. The name of the attachments should refer to the part number of the detail line.

The input XML file looks like this:

The file contains 4 Sales_Invoice_Line nodes and inside we want to extract the value of the Line_No node and use that as a part of the attachment name in an outgoing email.

A workflow that can do that is shown below. The payload is the demo invoice xml as shown above.


From the left it contains these components:
Choice and join
The first component is the choice and join component. That is used in order to be able to run components after all the attachments has been created. It is here setup with a dummy condition, that is always true and the otherwise branch has been deleted as it is not required.

Here it is setup as below:

The condition true() refers to the XPath function, true(), but you could e.g. also use a dummy condition like 1=1.

The reason for using this component is, that when we reach the join branch, then we know all attachments has been created.
Structural split
Here the structural split is setup as below:


The Collect attachments option is enabled, which is required for keeping all of the attachments.
Create PDF document
With the Create PDF document component we create a PDF file in the payload, which is later to be kept as an attachment. The component setup is as below:

The template referenced is the normal template used for the demo invoice xml file and that is possible as the structure of the XML is the same - although it only contains just a single detail line.
Set attachment name
With the Set attachment name component we prepare for the name for the attachment, that we are about to create. We want a unique name for the attachment so the XPath expression below is used:


The expression is: concat('Document_',/IF_Type/Sales_Invoice/Sales_Invoice_Header/Sales_Invoice_Line[1]/Line_No,'.pdf')
This will name the attachments: Document_ followed by the value of the Line_No node in the detail line followed by '.pdf'.
You may notice the [1] to the right of the Sales_Invoice_Line. This is done in order to avoid a warning in the workflow editor as the sample file (Demo_invoice.xml) contains 4 Sales_Invoice_Line nodes, but in reality at this stage the payload will contain just a single "Sales_Invoice_Line" node.


Payload to attachment
Now we can create an attachment with the payload and attachment name, that has already been set. This is done with the component, Payload to attachment, which has no parameters:


Send an HTML email
In this final stage we create the email. The email in this case should only have the attachments, that are already created. So the component, Send an HTML email is chosen.

It is setup as shown in the image below:

Here the email is held, so it is not sent anywhere, but the resulting eml file can be downloaded from the email log.

Here is how the email looks:




 



    • Related Articles

    • Split XML

      This advanced converter workflow component can split up an XML in the payload of the current workflow. The subtree of this workflow component is executed for each splitted XML. It is highly recommended to consider the Structural split component ...
    • Transform or split

      The transform or split workflow component is able to transform and/or split an input XML file. The subtree of this workflow component is executed for each splitted/transformed XML. For splitting an XML file the workflow component, Structural split is ...
    • Split spool (complex key)

      A spooled file can be split into smaller files depending on the contents e.g. to split up a larger spooled file with many invoices into individual invoices. If the other spooled file split functions are not enough, then you can consider this workflow ...
    • Spooled file split

      You might want to split up spooled files during InterFormNG2 processing. The reason might be, that the input spooled file may contain multiple documents (e.g. invoices), and that you want to create one PDF file (or email) for each invoice. There are ...
    • Split spool (fixed key position)

      If you want InterFormNG2 to process spooled files, that contains multiple documents e.g. multiple invoices within a single spooled file (e.g. generated by a batch invoice run), then you may want to split up the spooled file into multiple output PDF ...