XML Anonymizer Bean in Communication Channel to remove namespace prefix in XML Payload

By Suraj Pabbathi, Yash Technologies Inc

There are situations where additional functions are demanded to satisfy a requirement. The requirement could be to remove namespace prefix in XML Payload. Modules equipped in the adapter come for rescue without having the developer to do much.

The modules are the basis of the adapter configuration on the Parameters tab page, located in the module processor and are displayed in the module processor once a communication channel has been created.

A little about Namespaces…

One of the primary motivations for defining an XML namespace is to avoid naming conflicts when using and re-using multiple times. XML Schema is used to create vocabulary for an XML instance, and uses namespaces.

Namespaces are like package in Java, has many reusable elements and attributes.

For eg: <ns0:ShipNotice xmlns:ns0="urn:cidx:names:specification:ces:schema:all:4:0" Version="4.0">

In the attribute xmlns:ns0, xmlns is a reserved word, used to declare a namespace. That is the above example is read as binding the prefix ‘ns0’ with the namespace ‘urn:cidx:names:specification:ces:schema:all:4:0’.

It is convention in PI to use ns0 as the prefix for the XML Schema namespace. And wherever the prefix ‘ns0’ is used in the entire message, they are used only as a placeholder and must be expanded by the namespace. This way all the elements used in the message are associated to the namespace using the prefix.

The example message is given below, where every element (Header, DocumentIdentifier etc..) are associated with the namespace ‘urn:cidx:names:specification:ces:schema:all:4:0’.

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

<ns0:ShipNotice xmlns:ns0="urn:cidx:names:specification:ces:schema:all:4:0" Version="4.0">






However, business partner who receives this message may think that XML document is cluttered with prefix ns0 and want to avoid. Or it could be that the software used does not support this prefix and will not process the messages successfully. So now the requirement dictates the removal of prefix without removing the namespace. As explained, in PI it is possible to remove the namespace prefix using XML Anonymizer bean in module that is equipped in adapter.  

Find below the screenshot that illustrates the configuration of the communication channel.  


Add the Module in the Processing Sequence

1.       Insert the module before the adapter module.

Module Name : AF_Modules/XMLAnonymizerBean

Module Key: 0  

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

Add Parameters in the Module Configuration  

2.       Module Key: 0

Parameter Name: anonymizer.acceptNamespaces

Parameter Value: <namespace> ‘’

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).  

3.       Module Key: 0

Parameter Name: anonymizer.quote

Parameter Value: ‘

Here specify the character to be used to enclose the attribute values.  The default value is ‘.  

When scenario is executed, the target message contains the namespace with no prefix.  

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

<ShipNotice xmlns="urn:cidx:names:specification:ces:schema:all:4:0" Version="4.0">






There are generic modules for adapters provided by SAP for different requirements. Navigate to http://help.sap.com/saphelp_nwpi711/helpdata/en/cd/5af7c0c994e24fb0d0088443513de2/frameset.htm for more details.

Please send us your feedback/suggestions at webmaster@SAPTechnical.COM 

HomeContribute About Us Privacy Terms Of Use • Disclaimer • SafeCompanies: Advertise on SAPTechnical.COM | Post JobContact Us  

Graphic Design by Round the Bend Wizards

footer image footer image