My colleagues and I, we have been having lots of requirements around filtering the XML content. The blog
https://blogs.sap.com/2017/06/01/sap-cloud-platform-integration-content-filter-in-detail/ explains most of the cases and helped in understanding Filter content in CPI.
I had referred to this blog for my XPath expressions to filter the xml contents but the problem was I had to deploy my scenario after every change to see whether it is working as expected. On doing a little research on Eclipse, I came across with the view XPath in Eclipse. It shows you the output of the expression without having to deploy it in the server.
Scenario: Fetching OData from SuccessFactors and using filter to extract data based on the condition provided in XPath Expression in content filter.
Before starting with the test cases, create an XML file from the already generated XSD in your project:
- Right Click on your project -> New - > Other
- Choose XML file from XML as shown below
- Enter Next and enter your file name and the project.
- Enter Next and select the below option:
- Select the XSD created from the OData Query and enter Finish
In my case, I used the same example as that is used by Sriprasad to make it easy to relate and test.
Edit the XML with your content and you are ready to test using XPath view.
Go to Windows - > Show View -> Other and select XPath from XML as shown below:
The below window pops Up:
Case 1: Filter the XML containing <Error> node. Provide the xPath expression in the editor as shown below and the output will be displayed in Location
Case 2: Filters the Record node which contains
<Status> node with value S [Success] or SK [Skipped]
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.
Case 4: Filter the incoming XML not containing
<Error> Node
We can use many more complex filters and check if our XPath expression is correct using this feature and save the time to test in the server directly every time a change is made.
Thanks to my colleague Jwalith for helping me in this scenario.