We may have to nurture with the namespaces in the payload before posting to the end system.The requirement could be to remove namespace prefix in XML Payload.This module then can help the developer without writing long XSLT codes to achieve the result.
First let us understand the basics of Namespace.
What is a namespace?
Ans:XML namespaces are used for providing uniquely named elements and attributes in an XML document.
Use?
Ans:XML namespace is to avoid naming conflicts when using and re-using multiple times.
How we use it in the XML?
Ans:Example below.
<ns0:tablexmlns:ns0="http://www.w3.org/TR/html4/">
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 ‘http://www.w3.org/TR/html4/’
Now let us see the use of the XML Anonymizer Bean in real case.
We had a scenario where the output was like below after the mapping in PI.
<?xml version="1.0" encoding="UTF-8"?>
<soap:Envelopexmlns:soap="http://schemas.xmlsoap.org/soap/envelope/"xmlns:xsd="http://www.w3.org/2001/XMLSchema"xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<soap:Body>
<ns1:ImportStringxmlns:ns1="http://xyz.com/">
<ns1:filename>test.xml</ns1:filename>
<ns1:payload>xxx</ns1:payload>
</ns1:ImportString>
</soap:Body>
</soap:Envelope>
However the customer wanted us to remove the prefix of ns1 without removing the namespace.However they wanted the soap,xsd and xsi prefix and namespace both to be there at the output. So they wanted a structure like below.
<?xml version="1.0" encoding="UTF-8"?>
<soap:Envelopexmlns:soap="http://schemas.xmlsoap.org/soap/envelope/"xmlns:xsd="http://www.w3.org/2001/XMLSchema"xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<soap:Body>
<ImportStringxmlns="http://xyz.com/">
<filename>test.xml</filename>
<payload>xxx</payload>
</ImportString>
</soap:Body>
</soap:Envelope>
To do this we had to use the XML Anonymizer Bean like below
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: http://www.w3.org/2001/XMLSchema-instance xsi http://www.w3.org/2001/XMLSchema xsd http://schemas.xmlsoap.org/soap/envelope/ soap http://xyz.com/ ''
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).
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 ‘.
Once we activate all the above configurations and execute the scenario we get the desired output as below.
<soap:Envelopexmlns:soap="http://schemas.xmlsoap.org/soap/envelope/"xmlns:xsd="http://www.w3.org/2001/XMLSchema"xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<soap:Body>
<ImportStringxmlns="http://xyz.com/">
<filename>test.xml</filename>
<payload>xxx</payload>
</ImportString>
</soap:Body>
</soap:Envelope>