cancel
Showing results for 
Search instead for 
Did you mean: 

How to add a name space to header and body

former_member192238
Participant
0 Kudos

Hello Experts,

My interface is proxy to soap sync scenario i have to create XSD for source and target based on the XML provided by the business for that i have created dummy DT,MT and MM  now the task is i have to add namepaces to Header and body in the XML structure which is as follow.

<soapenv:Header>

        <sanco-xmlgate:Security xmlns:sanco-xmlgate="http://sasbos.ws.in.xmlgatev2.sanco.cec.eu">

            <UsernameToken>

                <Username>xxxxx</Username>

                <Password>yyyyyPassword>

<Secret>zzzzzz</ Secret >

            </UsernameToken>

        </sanco-xmlgate:Security>

        <sanco-xmlgate:xmlgate xmlns:sanco-xmlgate="http://sasbos.ws.in.xmlgatev2.sanco.cec.eu">

            <sanco-xmlgate:project id="193" />

            <sanco-xmlgate:service name="importStatus.cfc" method="checkImportProduct" />

        </sanco-xmlgate:xmlgate>

    </soapenv:Header>

<soapenv:Body>

        <sanco-xmlgate:checkImportProduct soapenv:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/">

            <sanco-xmlgate:parameterStr country="BE" document_key="70B9EFF4-EF61-4718-0824057D6E" document_version="1" xsi:type="xsd:string">3|1290-67</sanco-xmlgate:parameterStr>

        </sanco-xmlgate:checkImportProduct>

    </soapenv:Body

Based on the above XMl i have created Mt which i have used in dummy Mapping to see the XML structure which is as follow.

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

<ns0:Envelope xmlns:ns0="http://xyz.com/Xproc/ProcComm/XML/OTHERS/xi">
   <soapenv_Header>
      <sanco_xmlgate_Security>
         <UsernameToken>
            <Username/>
            <Password/>
            <Secret/>
         </UsernameToken>
      </sanco_xmlgate_Security>
      <sanco_xmlgate_xmlgate>
         <sanco_xmlgate_project id=""/>
         <sanco_xmlgate_service name="" method=""/>
      </sanco_xmlgate_xmlgate>
   </soapenv_Header>
   <soapenv_Body>
      <sanco_xmlgate_checkImportProduct>
         <sanco_xmlgate_parameterStr country="" document_version="" Type="" document_key=""/>
      </sanco_xmlgate_checkImportProduct>
   </soapenv_Body>
</ns0:Envelope>

In the above XML how i can get the namespace to following Nodes

sanco-xmlgate:Security xmlns:sanco-xmlgate="http://sasbos.ws.in.xmlgatev2.sanco.cec.eu"> 

            <UsernameToken>

<sanco-xmlgate:xmlgate xmlns:sanco-xmlgate="http://sasbos.ws.in.xmlgatev2.sanco.cec.eu">

sanco-xmlgate:checkImportProduct soapenv:encodingStyle="http://schemas.xmlsoap.org/soap/encoding

How i can acheive the above requirement any suugestions are highly apprecaited.

Regards

Praveen Reddy

Accepted Solutions (0)

Answers (2)

Answers (2)

iaki_vila
Active Contributor
0 Kudos

Hi Praveen,

You can use two mappings for this, one after another in the operation mapping (interface mapping). The first mapping you generate the desired tag without namespaces and in the second you can use a XSL mapping to generate the namespaces.

For example, in the first you obtain the XML that you pointed below:

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

<ns0:Envelope xmlns:ns0="http://xyz.com/Xproc/ProcComm/XML/OTHERS/xi">

    <soapenv_Header>

        <sanco_xmlgate_Security>

            <UsernameToken>

                <Username>User</Username>

                <Password>x</Password>

                <Secret/>

            </UsernameToken>

        </sanco_xmlgate_Security>

        <sanco_xmlgate_xmlgate>

            <sanco_xmlgate_project id="">Project</sanco_xmlgate_project>

            <sanco_xmlgate_service name="" method="">Service</sanco_xmlgate_service>

        </sanco_xmlgate_xmlgate>

    </soapenv_Header>

    <soapenv_Body>

        <sanco_xmlgate_checkImportProduct>

            <sanco_xmlgate_parameterStr country="" document_version="" Type="" document_key="">Parameter</sanco_xmlgate_parameterStr>

        </sanco_xmlgate_checkImportProduct>

    </soapenv_Body>

</ns0:Envelope>

Then you can use an XSL mapping: (i do the mapping may be i missunderstood any of your requeriments)

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

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

    <xsl:template match="/">

        <ns0:Envelope xmlns:ns0="http://xyz.com/Xproc/ProcComm/XML/OTHERS/xi">

            <soapenv_Header>

                <sanco-xmlgate:Security xmlns:sanco-xmlgate="http://sasbos.ws.in.xmlgatev2.sanco.cec.eu">

                    <xsl:copy-of select="ns0:Envelope/soapenv_Header/sanco_xmlgate_Security/UsernameToken/."/>

                </sanco-xmlgate:Security>

                <sanco-xmlgate:xmlgate xmlns:sanco-xmlgate="http://sasbos.ws.in.xmlgatev2.sanco.cec.eu">

                    <xsl:copy-of select="ns0:Envelope/soapenv_Header/sanco_xmlgate_xmlgate/sanco_xmlgate_project/."/>

                    <xsl:copy-of select="ns0:Envelope/soapenv_Header/sanco_xmlgate_xmlgate/sanco_xmlgate_xmlgate/."/>

                </sanco-xmlgate:xmlgate>

            </soapenv_Header>

            <soapenv_Body>

              <sanco-xmlgate:checkImportProduct xmlns:sanco-xmlgate="http://sasbos.ws.in.xmlgatev2.sanco.cec.eu">

                    <xsl:copy-of select="ns0:Envelope/soapenv_Body/sanco_xmlgate_checkImportProduct/sanco_xmlgate_parameterStr/."/>

                </sanco-xmlgate:checkImportProduct>

            </soapenv_Body>

        </ns0:Envelope>

    </xsl:template>

</xsl:stylesheet>

And finally you obtain this XML:

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

<ns0:Envelope xmlns:fo="http://www.w3.org/1999/XSL/Format" xmlns:ns0="http://xyz.com/Xproc/ProcComm/XML/OTHERS/xi">

    <soapenv_Header>

        <sanco-xmlgate:Security xmlns:sanco-xmlgate="http://sasbos.ws.in.xmlgatev2.sanco.cec.eu">

            <UsernameToken>

                <Username>User</Username>

                <Password>x</Password>

                <Secret/>

            </UsernameToken>

        </sanco-xmlgate:Security>

        <sanco-xmlgate:xmlgate xmlns:sanco-xmlgate="http://sasbos.ws.in.xmlgatev2.sanco.cec.eu">

            <sanco_xmlgate_project id="">Project</sanco_xmlgate_project>

        </sanco-xmlgate:xmlgate>

    </soapenv_Header>

    <soapenv_Body>

        <sanco-xmlgate:checkImportProduct xmlns:sanco-xmlgate="http://sasbos.ws.in.xmlgatev2.sanco.cec.eu">

            <sanco_xmlgate_parameterStr country="" document_version="" Type="" document_key="">Parameter</sanco_xmlgate_parameterStr>

        </sanco-xmlgate:checkImportProduct>

    </soapenv_Body>

</ns0:Envelope>

Regards.

former_member192238
Participant
0 Kudos

Hi,

Please suggest whether i can acheive this by using the external references or any thirdy party tools apart from XSL mappings.

Regards

Praveen

Former Member
0 Kudos

Hi Praveen,

you can achieved this by using XSD and import this in your xsd.

Please find the http://www.datypic.com/books/defxmlschema/chapter03.html which will be helpful for you.

Best Regards,

Sagarika Mishra

Former Member
0 Kudos

use the following link to generate the xsd from xml

http://www.freeformatter.com/xsd-generator.html

Import the generated xsd in the External Definition, you can go from there then.