cancel
Showing results for 
Search instead for 
Did you mean: 

several namespaces in root element

Former Member
0 Kudos

I have data types with different namespaces and I want to show them in the root element of the outgoing file.

In every data type I set the value of "Qualify Schema" to "Elements & Attributes".

With this the created file has only the XML Namespace of the message type in the root element as nw0. The other namespaces ns1..ns5 are created on every element. It looks like this:

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

<ns0:Order xmlns:ns0="http://xxx.Orders>

     <ns0:Customer>

          <ns1:Name xmlns:ns1="http://xxx.Customer">My Name</ns1:Name>

          <ns1:Address xmlns:ns1="http://xxx.Customer">My Address</ns1:Address>

     </ns0:Customer>

     <ns0:Items>

          <ns0:Item>

               <ns3:Article xmlns:ns3="http://xxx.Article">My Article</ns3:Article>

               <ns3:Description xmlns:ns3="http://xxx.Article">My Description</ns3:Description>

          </ns0:Item>

          </ns0:Item>

     </ns0:Items>

</ns0:Order>

Can PI create a message with several namespaces in the root element. What I want to have is this:

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

<ns0:Order xmlns:ns0="http://xxx.Orders

                 xmlns:ns1="http://xxx.Customer"

                 xmlns:ns3="http://xxx.Article">

     <ns0:Customer>

          <ns1:Name>My Name</ns1:Name>

          <ns1:Address>My Address</ns1:Address>

     </ns0:Customer>

     <ns0:Items>

          <ns0:Item>

               <ns3:Article>My Article</ns3:Article>

               <ns3:Description>My Description</ns3:Description>

          </ns0:Item>

          </ns0:Item>

     </ns0:Items>

</ns0:Order>

Accepted Solutions (0)

Answers (3)

Answers (3)

iaki_vila
Active Contributor
0 Kudos

Hi Michael,

With XSL you can do it in a few lines.

With Input:


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

<ns0:Order xmlns:ns0="http://xxx.Orders">

     <ns0:Customer>

          <ns1:Name xmlns:ns1="http://xxx.Customer">My Name</ns1:Name>

          <ns1:Address xmlns:ns1="http://xxx.Customer">My Address</ns1:Address>

     </ns0:Customer>

     <ns0:Items>

          <ns0:Item>

               <ns3:Article xmlns:ns3="http://xxx.Article">My Article</ns3:Article>

               <ns3:Description xmlns:ns3="http://xxx.Article">My Description</ns3:Description>

          </ns0:Item>

     </ns0:Items>

</ns0:Order>

You use this XSL:


<?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"/>

    <xsl:template match="./child::*">

        <ns0:Order xmlns:ns0="http://xxx.Orders" xmlns:ns1="http://xxx.Customer" xmlns:ns3="http://xxx.Article">

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

        </ns0:Order>

    </xsl:template>

</xsl:stylesheet>

You wil get this output:


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

<ns0:Order xmlns:ns0="http://xxx.Orders" xmlns:ns1="http://xxx.Customer" xmlns:ns3="http://xxx.Article">

    <ns0:Customer>

        <ns1:Name xmlns:ns1="http://xxx.Customer">My Name</ns1:Name>

        <ns1:Address xmlns:ns1="http://xxx.Customer">My Address</ns1:Address>

    </ns0:Customer>

    <ns0:Items>

        <ns0:Item>

            <ns3:Article xmlns:ns3="http://xxx.Article">My Article</ns3:Article>

            <ns3:Description xmlns:ns3="http://xxx.Article">My Description</ns3:Description>

        </ns0:Item>

    </ns0:Items>

</ns0:Order>

Regards.

gagandeep_batra
Active Contributor
0 Kudos

You Are good...:)

Former Member
0 Kudos

Hi Michael,

You can use Java mapping to achieve this requirement.

Regards,

Pranav

Harish
Active Contributor
0 Kudos

Hi Michael,

PI graphical mapping can not merge all the namespace into root node, you need to use XSLT or Java map to achieve that.

I would like to know why you want to merge all the namespace to root node?

Regards,

Harish

Former Member
0 Kudos

Hi Harish,

the messages will be sent to a supplier system and they want to have it like this.

I found some older discusstions to solve this with Java mapping, but I was hopefully to do it with the graphical tools.

Regards

Michael

Harish
Active Contributor
0 Kudos

Hi Michael,

You can try with having external definition as a target structure in your map. External definition root needs to define with all the required target namespace.

The only problem is if one of the node is option and did not populate in the structure, then also you will get all the namespace.

I never tried this, but i hope this will work.

Regards,

Harish

markangelo_dihiansan
Active Contributor
0 Kudos

Hello Michael,

Using graphical mapping, PI can only support one namespace in a root node. The other namespaces get "distributed" to their respective fields. Having said that,

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

<ns0:Order xmlns:ns0="http://xxx.Orders" xmlns:ns1="http://xxx.Customer" xmlns:ns2="http://xxx.Article">

   <ns0:Customer>

      <ns1:Name/>

      <ns1:Address/>

   </ns0:Customer>

   <ns0:Items>

      <ns0:Item>

         <ns2:Article/>

         <ns2:Description/>

      </ns0:Item>

   </ns0:Items>

</ns0:Order>

and

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

<ns0:Order xmlns:ns0="http://xxx.Orders>

     <ns0:Customer>

          <ns1:Name xmlns:ns1="http://xxx.Customer">My Name</ns1:Name>

          <ns1:Address xmlns:ns1="http://xxx.Customer">My Address</ns1:Address>

     </ns0:Customer>

     <ns0:Items>

          <ns0:Item>

               <ns3:Article xmlns:ns3="http://xxx.Article">My Article</ns3:Article>

               <ns3:Description xmlns:ns3="http://xxx.Article">My Description</ns3:Description>

          </ns0:Item>

          </ns0:Item>

     </ns0:Items>

</ns0:Order>

are semantically equivalent, although the first one is cleaner. Maybe this blog would help since it uses UDF to assign namespaces:

http://scn.sap.com/community/pi-and-soa-middleware/blog/2012/11/05/message-mapping-play-around-with-...

Hope this helps,

Mark