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