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:table xmlns: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:Envelope xmlns: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:ImportString xmlns: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:Envelope xmlns: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>
  
<ImportString xmlns=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

Anonymizer.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: 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:Envelope xmlns: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>
  
<ImportString xmlns=http://xyz.com/>
  
<filename>test.xml</filename>
  
<payload>xxx</payload>
  
</ImportString>
  
</soap:Body>
</soap:Envelope>


Now how to replace namespace? Check this Replace Namespace in PI by XMLAnonymizer Bean in communication channel-Example step by step

To report this post you need to login first.

11 Comments

You must be Logged on to comment or reply to a post.

    1. Arijit Mukherjee Post author

      Hi Avinash,

      In our requirement we needed to keep the below prefix and namespaces.

      xmlns:soap=http://schemas.xmlsoap.org/soap/envelope/

      xmlns:xsd=http://www.w3.org/2001/XMLSchema

      xmlns:xsi=http://www.w3.org/2001/XMLSchema-instance

      However we were asked to remove the prefix “ns1” but keep the corresponding namespace.

      xmlns:ns1=http://xyz.com/


      And as per the rule,you need to mention the namespaces and their prefix separated by a space if you want to keep them at output. And if you want a namespace without a prefix, enter ” (two single quotation marks). So we had to form the below value for that parameter.

      http://www.w3.org/2001/XMLSchema-instance xsi http://www.w3.org/2001/XMLSchema xsdhttp://schemas.xmlsoap.org/soap/envelope/soap http://xyz.com/


      If you notice carefully then you can see I have written all the namespace and prefix pair separated by space, whom I needed to get in the output and for the one where the prefix were needed to be suppressed,I mentioned ” in the place of prefix for its corresponding namespace.

      Thanks,

      Arijit

      (0) 
          1. Mohith M

            Hi Arijit,

            My requirement is to remove the header information in the soap envelope.

            In soap header i am getting some dummy data from source side.Is there ant chance to remove soap header with XMLAnonymizerBean.

            (0) 
              1. RAJESH NAIDU KURUGUNTLA

                Hi Arjit,

                Does this XML anonymizer bean works to remove namespace for SOAP Body element ?In your example to remove xmlns=http://xyz.com/ ?In my case the SOAP body element has <ns0:Element xmlns:ns0=”http://www.xxxxx.com/wfm/”> I need to remove the namespace but needs to replace the prefix ns0 with wfm for all the elements in the SOAP Body .

                Could you please let me know how we can do this?

                Thanks and Regards,
                Raj

                (0) 

Leave a Reply