Skip to Content
author's profile photo Former Member
Former Member

Need help to change prefix from ns1 to tns

Hi Experts ,

My scenario is Soap to File ( Sync) . Sender legacy system is expecting the response message with prefix tns in below format .

<tns:Data xmlns:tns="com.cad.xyz">

<HUMLast>00393155961240131287</HUMLast>

</tns:Data>

PI is able to send the response message in below format

<ns1:HumLastRequest xmlns:ns1="urn :cad.xyz">

<HUMLast>00393155965135748871</HUMLast>

</ns1:HumLastRequest>

How to remove Prefix ns1 and add prefix tns to match the requirement .

Expected result :

---------------------

<tns:HumLastRequest xmlns:tns="urn :cad.xyz">

<HUMLast>00393155965135748871</HUMLast>

</tns:HumLastRequest>

Please share any code if anyone has already gone through such requirements .

Note : I cannot use XMLAnonymizerBean at SOAP Sender channel as its a Synchronous scenario and response message need to have Prefix tns .

Add a comment
10|10000 characters needed characters exceeded

Assigned Tags

Related questions

4 Answers

  • Best Answer
    author's profile photo Former Member
    Former Member
    Posted on Jun 16, 2014 at 07:48 AM

    Aziz,

    Try this code, working fine.

    Paste the code in Attributes and Methods in Functions tab, Message Mapping Editor.

    public void transform(TransformationInput in, TransformationOutput out)

    throws StreamTransformationException {

    try {

    String sourcexml = "";

    String targetxml ="";

    String line ="";

    InputStream ins = in.getInputPayload().getInputStream();

    BufferedReader br = new BufferedReader( new InputStreamReader(ins));

    while ((line = br.readLine()) != null)

    sourcexml +=line+"\n";

    br.close();

    targetxml =sourcexml;

    targetxml = targetxml.replaceAll("ns0", "pfx");

    out.getOutputPayload().getOutputStream().write(targetxml.getBytes());

    }

    catch (Exception e)

    {

    throw new StreamTransformationException(e.getMessage());

    }

    }

    Thanks,

    Dhileep.

    Add a comment
    10|10000 characters needed characters exceeded

  • Posted on Jun 16, 2014 at 07:56 AM

    Hi,

    You can try with a XSL transformation:

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

    <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">

    <xsl:output method="xml" version="1.0" omit-xml-declaration="no" indent="yes"/>

    <xsl:template match="/">

    <tns:HumLastRequest xmlns:tns="urn :cad.xyz">

    <xsl:copy-of select="./child::*/child::*"/>

    </tns:HumLastRequest>

    </xsl:template>

    </xsl:stylesheet>

    I think it could be done more generally, but the last XSL example works too.

    Regards.

    Add a comment
    10|10000 characters needed characters exceeded

    • Former Member

      Hi Inaki,

      when i use the above xslt i get the below result

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

      <tns:HumResponse xmlns:tns="urn :cad.xyz">

      <HUMLast xmlns:ns1="urn :cad.xyz">qwe</HUMLast>

      </tns:HumResponse>

      I am able to get the prefix tns at root node HumResponse but i am getting namespace xmls and ns1 at each node .

      do i need to change something in the xslt code ?

      regards,

      Aziz khan .

  • Posted on Jun 16, 2014 at 09:29 AM

    Hi Aziz

    You can use that bean For response message, place the module after the adapter module call.

    check below blog for more info

    Handling namespaces in PI using XMLAnonymizerBean - Important factors:



    Regards

    GB


    Add a comment
    10|10000 characters needed characters exceeded

  • Posted on Jun 16, 2014 at 09:59 AM
    Add a comment
    10|10000 characters needed characters exceeded

Before answering

You should only submit an answer when you are proposing a solution to the poster's problem. If you want the poster to clarify the question or provide more information, please leave a comment instead, requesting additional details. When answering, please include specifics, such as step-by-step instructions, context for the solution, and links to useful resources. Also, please make sure that you answer complies with our Rules of Engagement.
You must be Logged in to submit an answer.

Up to 10 attachments (including images) can be used with a maximum of 1.0 MB each and 10.5 MB total.