Introduction:

This blog is to demonstrate usage of content Filter step of message Transformation in SAP Cloud Platform Integration.

Content Filter step filters required node or list of nodes or value of specific node from the incoming XML message.

Content Filter consist of below

Name Valid Logical name for Filter
XPath Expression Enter an XPATH to extract a node in the message
Value Type Specify the type for the value you want to extract from
XML Node

Below table provides the different type of Value Type returned from Filter.

String Returns the String value from Node INPUT:
<NODE>VALUE1</NODE>
XPATH: //NODE
OUTPUT: VALUE1
Integer Returns the Integer value from Node INPUT:<NODE>1</NODE>
XPATH: //NODE
OUTPUT: 1
Boolean Returns the Boolean value from Node INPUT:
<NODE>VALUE1</NODE>
XPATH: //NODE
OUTPUT: True
Node Returns the Node value from input xml INPUT:
<NODE>VALUE1</NODE>
XPATH: //NODE
OUTPUT:
<NODE>VALUE1</NODE>
Nodelist Returns list of nodes from incoming XML INPUT:
<Root>
<NODE>VALUE1</NODE>
<NODE1>VALUE1</NODE1>
</Root>
XPATH: //NODE
OUTPUT:
<Root>
<NODE>VALUE1</NODE>
<NODE1>VALUE1</NODE1>
</Root>

Use Cases:

Since the Value Types with Sting,Integer,Boolean and Node are self explanatory will get into Nodelist which we use more often in Custom Integration.

Case#1:

Filter the incoming XML containing <ErrorNode>

Input:

XPATH:

/Root/Record[Error]

Output:

Case#2:

Filters the Record node which contains <Status> node with value S [ Success ] or SK [ Skipped ].

Input:

XPATH:

/Root/Record[(Log/Status/text()= ‘S’ ) or (Log/Status/text() = ‘SK’ )]

Output:

Case#3:

Filters the Record node which contains <Data1> node with value having string length greater than or equal to 2 and <Data2> value not equal to blank.

Input:

XPATH:

/Root/Record[((string-length(Data1))>=2) and (Data2!=”)]

Output:

Case#4:

Filter the incoming XML not containing <ErrorNode>

Input:

XPATH:

/Root/Record[not(Error)]

Output:

Case#5:

Filter the incoming XML record containing  only values which are present in Property .

Input:

Content Modifier:

XPATH:

/Root/Record[contains($PropData1,Data1)]

Output:

Design Use Case:

Lets take a example  that you need to perform action on input data containing both valid and invalid data and need to take further action on only valid set of data.Whenever we get this kind of requirement we use to go with Splitter and Gather ( Since we are expecting group of records post validation ) and in between we will try to route the invalid data but you will end up in error ( Since Router step is not allowed between Splitter and Gather ). Content Filter comes to your help when you have these kind of requirement ( Same will be demonstrated in below image ) where 2 difference branches will have set of valid and invalid data .

Limitation:

  • It works only for XML messages:
  • Content Modifier to be used post Filter step to rebuild the Valid XML since Filter removes the Root node.

References:

Conclusion :

Very useful step which can be leveraged for data validation or filter and group incoming XML based on some condition.

Thanks to my friend Vinay for helping out in few use cases.:)

Regards,

Sriprasad Shivaram Bhat

 

To report this post you need to login first.

9 Comments

You must be Logged on to comment or reply to a post.

  1. Biplab Das

    Well explained. Is it possible to use multiple and complex x-path expressions?

    For example – consider a scenario where employees without ” Compensation” information and “nationalID should be filtered out from the Successfactors “Compound Employee” API XML. Is it possible achieve this with content filter?

     

    (0) 
    1. Sriprasad Shivaram Bhat Post author

      Hello Biplab,

      Its possible to have complex condition also ,but you need to make sure these conditions are grouped together in proper manner.

      I have just created a condition for above case including few more cases.

      queryCompoundEmployeeResponse/CompoundEmployee[((person/logon_user_is_active = ‘true’) and ((person/employment_information/job_information/emplStatus =’A’) and (person/employment_information/job_information/emplStatus/event_reason =’HIRNEW’)) and (person/employment_information/compensation_information) and (person/national_id_card)) ]

      Regards,

      Sriprasad Shivaram Bhat

      (1) 
  2. Aditya W. Sharma

    Very nicely explained with use cases, it would be a lot of benefit for developers in HCI to implement requirements based on your use cases. Keep blogging and sharing

    (1) 

Leave a Reply