Skip to Content
Author's profile photo Merina Acharya

Working with XPaths in Eclipse for CPI

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.

 

 

 

 

Assigned Tags

      7 Comments
      You must be Logged on to comment or reply to a post.
      Author's profile photo Nishant Bhatia
      Nishant Bhatia

      Awesome work Merina.. keep blogging 🙂

      Author's profile photo Merina Acharya
      Merina Acharya
      Blog Post Author

      Thanks Nishant

      Author's profile photo Michelle Crapo
      Michelle Crapo

      Nice one. It's been a really long time since I've used XPATHs.  This is a great refresher and I've learned something new!

      Michelle

      Author's profile photo Siva Naga Ravi Tejs Bommidala
      Siva Naga Ravi Tejs Bommidala

      Very Helpful! Nice Blog

      Author's profile photo Rajesh Kumar
      Rajesh Kumar

      Nice blog!! this helped me to become aware of this feature. I was using earlier some external tools for testing the XPath.

       

      Keep blogging !!

      Author's profile photo Eng Swee Yeoh
      Eng Swee Yeoh

      Hi Merina

       

      Thanks for highlighting such a goodie in Eclipse. I had previously used one of the plugins in Notepad++, but having this in Eclipse is much better. This will definitely come in handy in many CPI developments.

      I tried it out and it doesn't seem to work when an XML has namespace prefix. This made me curious and I looked up on it, and found the Eclipse XPath evaluation plugin that does have namespace support.

       

      Regards

      Eng Swee

      Author's profile photo Former Member
      Former Member

      Hi Merina

      Nicely written blog!!, keep blogging.

       

      Regards

      Swatantra