Technology Blogs by Members
Explore a vibrant mix of technical expertise, industry insights, and tech buzz in member blogs covering SAP products, technology, and events. Get in the mix!
cancel
Showing results for 
Search instead for 
Did you mean: 
jantuma
Discoverer

In this tutorial, we will explore different approaches to utilize the Content Filter for XML record filtration. The Filter component comprises three configurable fields:





  • XPath Expression – This field defines the filtering rule to be applied to the incoming XML body. We can specify an XPath expression that matches the desired elements or attributes within the XML structure.




  • Value type – This field determines the type of value that will be returned by the filter. Depending on the configuration, the filter can return various types of data




  • Name – This field provides an optional name for the filter, allowing us to assign a descriptive identifier to differentiate multiple filters if needed. By default, the name is set as "Filter 1.”




In the following table is shown what each value type returns









































Value type



Input



XPath



Output



String



<root>


     <node1>Value1<node1>


     <node2>Number1</node2>


</root>



//node1



Value1



Integer



//node2



Number1



Boolean



//node1



true



Node



//node2



<node2>Number1</node2>



Nodelist



//node1



<root>


     <node1>Value1<node1>


     <node2>Number1</node2>


</root>






Throughout this tutorial different strategies for constructing XPath expressions will be demonstrated.







Create iFlow


To begin, let's create an integration flow (iFlow) in Integration Suite. The iFlow shown in the picture and serves as a simple demonstration of how the Filter component operates. The iFlow consists of two Content Modifiers (Input Body and Add Root Node) and one Filter component.



The purpose of the Input Body Content Modifier is to provide the initial XML body for the iFlow. The Add Root Node Content Modifier is used to add a root node to the XML structure. This step restores validity of the given XML structure.


Finally, we have the Filter component, which performs the actual filtering of XML records. This component utilizes the XPath Expression field to define the filtering rule based on specific criteria.


In the first content modifier (Input body) we insert the following input body



<PerAddressDEFLT>
<PerAddressDEFLT>
<lastModifiedDateTime>2022-02 16T10:38:06.000</lastModifiedDateTime>
<address3>Everwijnstraat</address3>
<city>Kamp</city>
<addressType>home</addressType>
<jobInfoNav>
<EmpJob>
<company>8127</company>
<userId>85004545</userId>
</EmpJob>
</jobInfoNav>
<startDate>2022-02-01T00:00:00.000</startDate>
</PerAddressDEFLT>
<PerAddressDEFLT>
<lastModifiedDateTime>2022-02-16T10:42:06.000</lastModifiedDateTime>
<address3>Everwijnstraat</address3>
<city>Denekamp</city>
<addressType>home</addressType>
<personIdExternal>85000131</personIdExternal>
<jobInfoNav>
<EmpJob>
<company>8127</company>
<userId>85000131</userId>
</EmpJob>
</jobInfoNav>
<startDate>2022-02-01T00:00:00.000</startDate>
</PerAddressDEFLT>
</PerAddressDEFLT>

 

Filter by date


Xpath expression:



/PerAddressDEFLT/PerAddressDEFLT[xs:dateTime(lastModifiedDateTime) ge xs:dateTime(‘2022-02-16T10:40:00’)]


This expression filters dates, which are greater or equal than date 2022-02-16T10:40:00’


Whole expression or just parts of the expression can also be written as variable.


For example:



/PerAddressDEFLT/PerAddressDEFLT[xs:dateTime(lastModifiedDateTime) ge xs:dateTime(${property.filterExpression})]

property.filterExpression variable can be set in groovy/ javascript scripts or in Content Modifier.


In a second content modifier we add root node. In the end message we get an valid output body. If the filter doesn’t find any record, it returns an empty body.



Output:



<PaymentInformationV3>
<PerAddressDEFLT>
<lastModifiedDateTime>2022-02-16T10:42:06.000</lastModifiedDateTime>
<address3>Everwijnstraat</address3>
<city>Denekamp</city>
<addressType>home</addressType>
<jobInfoNav>
<EmpJob>
<company>8127</company>
<userId>85000131</userId>
</EmpJob>
</jobInfoNav>
<address4>1</address4>
<startDate>2022-02-01T00:00:00.000</startDate>
</PerAddressDEFLT>
</PaymentInformationV3>

 

Filter by text


Xpath expression:



/PerAddressDEFLT/PerAddressDEFLT[not(contains(city, 'Denekamp'))]

Output:
<PaymentInformationV3>
<PerAddressDEFLT>
<lastModifiedDateTime>2022-02-16T10:42:06.000</lastModifiedDateTime>
<address3>Everwijnstraat</address3>
<city>Kamp</city>
<addressType>home</addressType>
<jobInfoNav>
<EmpJob>
<company>8127</company>
<userId>85000131</userId>
</EmpJob>
</jobInfoNav>
<address4>1</address4>
<startDate>2022-02-01T00:00:00.000</startDate>
</PerAddressDEFLT>
</PaymentInformationV3>

LowerCase translation:


In this case, all values of node “city” are lowercased and then compared with word ‘denekamp’. This approach is very useful when we want to remove case sensitivity in filter.


Xpath expression:



/PerAddressDEFLT/PerAddressDEFLT[contains(translate(city,'ABCDEFGHIJKLMNOPQRSTUVWXYZ','abcdefghijklmnopqrstuvwxyz'), 'denekamp')]

Output:



<PaymentInformationV3>
<PerAddressDEFLT>
<lastModifiedDateTime>2022-02-16T10:42:06.000</lastModifiedDateTime>
<address3>Everwijnstraat</address3>
<city>Denekamp</city>
<addressType>home</addressType>
<jobInfoNav>
<EmpJob>
<company>8127</company>
<userId>85000131</userId>
</EmpJob>
</jobInfoNav>
<address4>1</address4>
<startDate>2022-02-01T00:00:00.000</startDate>
</PerAddressDEFLT>
</PaymentInformationV3>

 

Filter with StartsWith()



Xpath expression:



/PerAddressDEFLT/PerAddressDEFLT[starts-with(city, 'Dene')]

Output:








<PaymentInformationV3>
<PerAddressDEFLT>
<lastModifiedDateTime>2022-02-16T10:42:06.000</lastModifiedDateTime>
<address3>Everwijnstraat</address3>
<city>Denekamp</city>
<addressType>home</addressType>
<jobInfoNav>
<EmpJob>
<company>8127</company>
<userId>85000131</userId>
</EmpJob>
</jobInfoNav>
<address4>1</address4>
<startDate>2022-02-01T00:00:00.000</startDate>
</PerAddressDEFLT>
</PaymentInformationV3>

 

Filter with AND/OR


It is also possible to combine Xpath expressions with AND and OR


XPath expression:



/PerAddressDEFLT/PerAddressDEFLT[address3 = 'Everwijnstraat' and jobInfoNav/EmpJob/userId = '85000131']

Output:
<PaymentInformationV3>
<PerAddressDEFLT>
<lastModifiedDateTime>2022-02 16T10:38:06.000</lastModifiedDateTime>
<address3>Everwijnstraat</address3>
<city>Kamp</city>
<addressType>home</addressType>
<jobInfoNav>
<EmpJob>
<company>8127</company>
<userId>85004545</userId>
</EmpJob>
</jobInfoNav>
<address4>1</address4>
<startDate>2022-02-01T00:00:00.000</startDate>
</PerAddressDEFLT>
</PaymentInformationV3>

XPath expression:



/PerAddressDEFLT/PerAddressDEFLT[address3 = 'Everwijnstraat' or jobInfoNav/EmpJob/userId = '85000131']

Output:
<PaymentInformationV3>
<PerAddressDEFLT>
<lastModifiedDateTime>2022-02 16T10:38:06.000</lastModifiedDateTime>
<address3>Everwijnstraat</address3>
<city>Kamp</city>
<addressType>home</addressType>
<jobInfoNav>
<EmpJob>
<company>8127</company>
<userId>85004545</userId>
</EmpJob>
</jobInfoNav>
<address4>1</address4>
<startDate>2022-02-01T00:00:00.000</startDate>
</PerAddressDEFLT>
<PerAddressDEFLT>
<lastModifiedDateTime>2022-02-16T10:42:06.000</lastModifiedDateTime>
<address3>Everwijnstraat</address3>
<city>Denekamp</city>
<addressType>home</addressType>
<jobInfoNav>
<EmpJob>
<company>8127</company>
<userId>85000131</userId>
</EmpJob>
</jobInfoNav>
<address4>1</address4>
<startDate>2022-02-01T00:00:00.000</startDate>
</PerAddressDEFLT>
</PaymentInformationV3>

 

Conclusion


The Filter component is an invaluable tool when working with XML data. It allows for efficient and precise filtering of XML records based on specified criteria using XPath expressions.












1 Comment
Labels in this area