Please enable JavaScript to view this site.

InterFormNG2 Manual

Navigation: Workflow > Workflow examples

Extract payload from sub-node in input XML

Scroll Prev Top Next More

In this example we want to extract an XML file, that is stored as a sub-node in an input XML file. This could e.g. be an XML file stored inside of a SOAP input file.

 

This input file could have contents similar to this:

 

 

<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/">

<SOAP-ENV:Header>

<fndcn:Message xmlns:fndcn="urn:ifsworld-com:schemas:fndcn" SOAP-ENV:mustUnderstand="1">

<fndcn:Type>SEND_FULL_XML_TO_CONNECT</fndcn:Type>

<fndcn:Function>PURCHASE_ORDER_PRINT_REP</fndcn:Function>

<fndcn:Sender>Ifs Application</fndcn:Sender>

<fndcn:Receiver>PURCHASE_ORDER_PRINT_REP_7042.0.xml</fndcn:Receiver>

<fndcn:SentAt>2024-07-29T10:58:32Z</fndcn:SentAt>

<fndcn:ExpiresAt>2024-08-05T10:58:32Z</fndcn:ExpiresAt>

<fndcn:KE_ENV>CFG</fndcn:KE_ENV>

<fndcn:EXTERNAL_MESSAGE_ID>aa0cb571-fad3-4ee0-b830-c552c7d53291</fndcn:EXTERNAL_MESSAGE_ID>

</fndcn:Message>

</SOAP-ENV:Header>

<SOAP-ENV:Body>

<PURCHASE_ORDER_PRINT_REP_REQUEST xmlns="urn:xxx-com:purchase_order_print_rep">

...

</PURCHASE_ORDER_PRINT_REP_REQUEST>

</SOAP-ENV:Body>

</SOAP-ENV:Envelope>

 

The XML file, that we want to extract is stored inside the SOAP-ENV:Body node. In this case that is:

 

<PURCHASE_ORDER_PRINT_REP_REQUEST xmlns="urn:xxx-com:purchase_order_print_rep">

...

</PURCHASE_ORDER_PRINT_REP_REQUEST>

 

We can do that with a workflow like below:

 

NG2ExtractXMLPayloadFromSubNode001

 

Each component is described below:

 

1. Read from file

The workflow input type is here read from file, but it could be many other including REST webservice basic or REST webservice OAuth2.0.

 

2. To base64

When we extract data from an input XML file we normally get the values from the nodes, but in this case we need to make the workflow consider to look at the input XML file as a string and one way to do that is to convert the payload into base64 with the component, To base64:

 

NG2WorkflowToBase640001

 

The component has no parameters.

 

 

3. Payload to workflow variable

In order to work on the initial payload we now copy the base64 encoded payload into the workflow variable, tempPayload with Payload to workflow variable:

 

NG2ExtractXMLPayloadFromSubNode002

 

 

4. Set one workflow variable

This is the important workflow component, where the magic happens. Here we update the workflow variable, tempPayload like below with the component, Set one workflow variable:

 

NG2ExtractXMLPayloadFromSubNode003

 

The XPath expression is:

substring-before(substring-after(ng:base64ToUTF8($tempPayload),'<SOAP-ENV:Body>'),'</SOAP-ENV:Body>')

 

- and it may look some confusing to start with, so let us take a look at each function starting from the inside:

 

First the function will be executed: ng:base64ToUTF8($tempPayload). This converts the base64 encoded contents in variable, tempPayload back into UTF-8. For reference below we can refer to the result of this as $X.

 

This UTF-8 encoded string is now the first parameter of the next function, substring-after.

If we consider the previous function to be referred to as $X, then the expression here is:

 

substring-after($X,'<SOAP-ENV:Body>') - which really is:

substring-after(ng:base64ToUTF8($tempPayload),'<SOAP-ENV:Body>')

 

The substring-after returns the part of the original payload that comes after <SOAP-ENV:Body>.

The result does contain the full information found inside that node, but it also contains the rest of the original payload.

Below we can refer to the result of this function as $Y.

 

The final part of the expression is the substring-before(), which is used for cutting the new value just before the text: "</SOAP-ENV:Body>":

substring-before($Y,'</SOAP-ENV:Body>') - which really is the full expression above:

substring-before(substring-after(ng:base64ToUTF8($tempPayload),'<SOAP-ENV:Body>'),'</SOAP-ENV:Body>')

 

 

5. From variable to payload

Now we can finally copy the contents of the variable back into the payload with the workflow component, From variable to payload:

NG2ExtractXMLPayloadFromSubNode004

 

 

6. To filesystem

Finally we choose here to save the new payload into the file system with the component, To filesystem as below:

 

NG2ExtractXMLPayloadFromSubNode005