Skip to Content
Author's profile photo Arijit Mukherjee

Replace Namespace in PI by XMLAnonymizer Bean in communication channel-Example step by step

Some real time scenario will require to have the specific namespaces as per receiver’s system however while PI does the mapping, it may not generate the payload with the exact/required namespace. In those cases we may need to remove/add/replace namespaces.

SAP has provided one JAVA Bean which could help us in case of removing/replacing namespaces. I have described how this bean can help in removing namespace(or corresponding prefix) at Remove Namespace in PI by XMLAnonymizer Bean in communication channel-Example step by step

 

In this blog we will see how this can help replacing the namespace.

 

We had one scenario where the output after mapping looks like below.

/wp-content/uploads/2014/10/pic1_559960.jpg

 

However our customer wanted the output like below.

 

/wp-content/uploads/2014/10/pic2_559994.jpg

So if you notice carefully then we needed below changes.

 

  • Remove the namespace prefix “ns0” however keep the corresponding namespace “urn:oasis:names:specification:ubl:schema:xsd:DespatchAdvice-2”
  • Replace the namespace prefix “ns2” with “cbc”
  • Replace the namespace prefix “ns3” with “cac”.

To do this,we have used the XML Anonymizer bean.

 

/wp-content/uploads/2014/10/pic3_559995.jpg

 

Here is the configuration procedure:

  • Add the Module in the Processing Sequence.Insert this Anonymizer module before the adapter module as shown above.

Module Name : AF_Modules/XMLAnonymizerBean

Module Type:Local Enerprise Bean

Module Key: 0

The module name ‘CallSapAdapter’ is default one that can be left as it is

 

  • Add Parameters in the Module Configuration.

Module Key: 0

Parameter Name: anonymizer.acceptNamespaces

Parameter Value:

urn:oasis:names:specification:ubl:schema:xsd:CommonBasicComponents-2 cbc urn:oasis:names:specification:ubl:schema:xsd:CommonAggregateComponents-2 cac urn:oasis:names:specification:ubl:schema:xsd:DespatchAdvice-2

Please note that in case you have any additional Namespaces and Prefix, you also need to maintain them in the Parameter Value along with the the changes/replacement in the same place. So if you have a namespace like soapenv:http://abc.com and you want to keep that along with above changes then the Parameter Value becomes like below.

http://abc.com soapenv urn:oasis:names:specification:ubl:schema:xsd:CommonBasicComponents-2 cbc urn:oasis:names:specification:ubl:schema:xsd:CommonAggregateComponents-2 cac urn:oasis:names:specification:ubl:schema:xsd:DespatchAdvice-2 ”

Assigned Tags

      8 Comments
      You must be Logged on to comment or reply to a post.
      Author's profile photo Former Member
      Former Member

      Good Blog Arijit..... Thanks for sharing

      Author's profile photo Former Member
      Former Member

      Hi Arijit,

      Good Blog, i have a question.

      With XML Anonymizer bean i can change the prefix of the namespace of the body but

      I can not change the prefix of the namespace of the header.

      You know how to solve this?




      Regards

      Author's profile photo Arijit Mukherjee
      Arijit Mukherjee
      Blog Post Author

      Hi,

      Use XSLT mapping.

      Thanks

      Arijit

      Author's profile photo Varun Goel
      Varun Goel

      Hi Arijit,

       

      I was able to replace the namespace, however new namespaces are not added in the xml file. Could you please confirm, if new namespaces can be added in the xml.

       

      Thanks

      varun

      Author's profile photo Manoj K
      Manoj K

      Varun,

      XML Anonymizer is used to retain/remove the namespace , you can't add new namespace with this.

      Br,

      Manoj

       

      Author's profile photo Khajamohedden Shaik
      Khajamohedden Shaik

      Hi Arijit,

       

      Thanks a lot for providing this document.

      I am able to replace the prefix values cac and cbc.

      But, as you mentioned above i am not able to remove prefix ns0 from namespace

      "urn:oasis:names:specification:ubl:schema:xsd:DespatchAdvice-2 ”.

      I have added the parameters as below.

       

      http://www.unece.org/cefact/namespaces/StandardBusinessDocumentHeader ns0 http://www.w3.org/2001/XMLSchema xs urn:oasis:names:specification:ubl:schema:xsd:CommonAggregateComponents-2 cac urn:oasis:names:specification:ubl:schema:xsd:CommonBasicComponents-2 cbc urn:oasis:names:specification:ubl:schema:xsd:DespatchAdvice-2 "

      and tried without " at DespatchAdvice-2, But, file not forming as xml.

      Could you please help me to remove ns0 from DespatchAdvice-2 name space.

      Thanks,

      Khaja S.

       

      Author's profile photo Khajamohedden Shaik
      Khajamohedden Shaik

      Issie resolved.

      I added double quotation instead of single two quotations.

      Enter a list of namespaces and their prefixes that are to be kept in the target XML document and to result a namespace without a prefix, enter ‘ ‘ (two single quotation marks).

      Author's profile photo Sivakumar Chandrasekaran
      Sivakumar Chandrasekaran

      Very Good Blog, Helped to understand the concepts. Thanks.