cancel
Showing results for 
Search instead for 
Did you mean: 

Interface Determination: Using Xpath with Soap Envelope

che_eky
Active Contributor
0 Kudos

Hi All,

I am having trouble using an Xpath expression in Interface Determination. The scenario is File to multiple Idoc but the source file contains an XML wrapped in a Soap Envelope like this:

<?xml version="1.0" encoding="utf-8"?>

<soap:Envelope xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">

   <soap:Body>

      <GetDataResponse xmlns="http://www.dummy.com/jdjen9/">

         <GetDataResult>

            <Elephant>

               <elephantName>Jumbo</elephantName>

               <elephantDetails>

                  <foodLimit>0</foodLimit>

               </elephantDetails>

               <elephantColour>

                  <colourCode/>

               </elephantColour>

               <zooAddresses>

                  <Address>

                     <addressCode>84475</addressCode>

                  </Address>

               </zooAddresses>

            </Elephant>

         </GetDataResult>

      </GetDataResponse>

   </soap:Body>

</soap:Envelope>

The interface is working fully but I would like to control Interface Determination based on a node in the XML. If the node called <Address> exists (shown in red above) then execute a particular operation mapping.

I have tried several Xpath expressions but they don't seem to work. Is it because Xpath does not expect the Soap envelope? If so is there another way to get what I want?

Some of what I have tried:

  1. /GetDataResponse/GetDataResult/Elephant/zooAddresses/Address EX
  2. /soap:Envelope/soap:Body/GetDataResponse/GetDataResult/Elephant/zooAddresses/Address EX

Any help appreciated.

Che

Accepted Solutions (1)

Accepted Solutions (1)

markangelo_dihiansan
Active Contributor
0 Kudos

Hi Che,

After much investigation, the cause why your xpath is not working is because of this namespace:


<GetDataResponse xmlns="http://www.dummy.com/jdjen9/">

This can be removed by using XMLAnonymizerBean

Adding XMLAnonymizerBean in the Module Processor - Adding Modules to the Module Processor - SAP Libr...

Sample test:

With Address (after Anonymizer transformation)

Without Address (after Anonymizer transformation)

Regards,

Mark

former_member190293
Active Contributor
0 Kudos

Hi Mark!

You got it! It looks to be the default behavour of namespace-by-default syntax ("xmlns=").

In this case expression like:

/p1:Envelope/p1:Body/p2:GetDataResponse/p2:GetDataResult/p2:Elephant/p2:zooAddresses/p2:Address EX

should work with setting p2 to "http://www.dummy.com/jdjen9/" in Expression editor.

Regards, Evgeniy.

markangelo_dihiansan
Active Contributor
0 Kudos

Hi Evgeniy,

Thanks! I'm afraid it would only work if there is a prefix for "http://www.dummy.com/jdjen9/". Not sure with the latest versions though as I am still on 7.11 SP13.

Regards,

Mark

former_member190293
Active Contributor
0 Kudos

Hi Mark!

You are absolutely right! PI sometimes treats XPath expressions in a strange manner.

In my XPath expressions testing tool expression:

/soap:Envelope/soap:Body/GetDataResponse/GetDataResult/Elephant/zooAddresses/Address

works so as :

/soap:Envelope/soap:Body/ns1:GetDataResponse/ns1:GetDataResult/ns1:Elephant/ns1:zooAddresses/ns1:Address

with "ns1" set to "http://www.dummy.com/jdjen9/" does.

Regards, Evgeniy.

markangelo_dihiansan
Active Contributor
0 Kudos

Thank you for the confirmation, it seems this is still the current behavior even for higher versions.

che_eky
Active Contributor
0 Kudos

Mark / Evgeniy,

From your last posts are you saying this can be achieved using only the Xpath expression editor in the interface Determination or do I need to use it in combination with XML AnoymizerBean in the module processor?

Che

former_member190293
Active Contributor
0 Kudos

Hi, Che!

First, you can try to set namespaces for your XPath in condition editor.

If it still doesn't work for you, you should use Mark decision.

You can start with setting prefixes only for Envelope and Body elements.

Just forgot, that you wouldn't be able to see these elements in editor as it's the part of SOAP Envelope.

Just try to set prefixes for all elements of your XPath expression to default namespace which is set in your message

Regards, Evgeniy.

former_member190293
Active Contributor
0 Kudos

But I think, the best way, if it's possible, is to set prefix for custom namespace in your source message.

Regards, Evgeniy.

che_eky
Active Contributor
0 Kudos

Hi Evgeniy and Mark,

Finally found an xpath expression that works! It makes sense now I think about it. Here is what I now have in the Interface Determination:

Add the following xpath expression:

  • /p2:Envelope/p2:Body/p1:GetDataResponse/p1:GetDataResult/p1:Elephant/p1:zooAddresses/p1:Address EX

Add the following two prefixes (both are needed):



With the above in place the node <Address> is successfully located and the correct Operation Mapping is now being called. Looking at one of the screen shots from Mark where he used "/p1:Envelope/p1:Body" gave me the idea to try the above.

Che

markangelo_dihiansan
Active Contributor
0 Kudos

Hi Che,

Thank you for showing the solution. It seems weird that you have to place prefixes even when it is present, but glad to know it is working. Perhaps you need to open an OSS about this since this is not standard xpath behavior.

Regards,

Mark

former_member190293
Active Contributor
0 Kudos

Hi, Che!

Glad to hear that. Yes, it works since you've marked elements with correct namespaces according to its definitions.

Regards, Evgeniy.

Answers (4)

Answers (4)

che_eky
Active Contributor
0 Kudos

Hi All,

First let me say that I am overwhelmed by all your offers of help, what a great community , thank you all.

Okay so it was a late night last night and I need time to go through all the suggestions this morning, but will do so today. I will get back to you with what I find.

Che

former_member190293
Active Contributor
0 Kudos

Hi Che!

Try //zooAddresses/Adress EX

Regards, Evgeniy.

markangelo_dihiansan
Active Contributor
0 Kudos

Hi Che,

In the expression editor, have you added the namespace for the soap prefix?

Regards,

Mark

Snavi
Active Participant
0 Kudos

Hi Che,

use the below expression

/GetDataResponse/GetDataResult/Elephant/zooAddresses[Address]   EX


or


//zooAddresses[Address]   EX

If this does not work, please provide the screenshot of the message type in your outbound interface