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.
However our customer wanted the output like below.
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.
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 ”
Good Blog Arijit..... Thanks for sharing
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
Hi,
Use XSLT mapping.
Thanks
Arijit
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
Varun,
XML Anonymizer is used to retain/remove the namespace , you can't add new namespace with this.
Br,
Manoj
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.
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).
Very Good Blog, Helped to understand the concepts. Thanks.