cancel
Showing results for 
Search instead for 
Did you mean: 

how to add mulitple namespace in xml

Former Member
0 Kudos

Hi,

I have this output xml:


<?xml version="1.0" encoding="utf-8" ?> 
- <E24B:E24B_Update_MachineCards_001 xmlns:E24B="urn:E24B_UpdateMachineCards_001">
- <E24B:DataArea>
- <E24B:UpdateMachineCards>
- <E24B:Machine>
- <E24B:Component>
  <f:ComponentSerNo xmlns:f="urn:fields">000000000000000456</f:ComponentSerNo> 
  <f:ComponentType xmlns:f="urn:fields">108</f:ComponentType> 
  </E24B:Component>
- <E24B:Market>
  <f:FinalMarket xmlns:f="urn:fields">TR</f:FinalMarket> 
  </E24B:Market>
  <f:SalesModel xmlns:f="urn:fields" /> 
  <f:SerialNo xmlns:f="urn:fields">000000000000000456</f:SerialNo> 
- <s:CntrolArea xmlns:s="urn:segments">
- <s:Bsr>
  <s:Noun>Machine Card</s:Noun> 
  <s:Verb>UPDATE</s:Verb> 
  </s:Bsr>
- <s:DateTime>
  <s:Dt_Qualifier>Creation</s:Dt_Qualifier> 
  <s:Dt_Value>20111207</s:Dt_Value> 
  <s:TimeZone>7200</s:TimeZone> 
-------------------------------------------------------------------------------


But this content is wrong.

The expected content should be as follows:




<?xml version="1.0" encoding="UTF-8" ?> 
- <E24B:E24B_Update_MachineCards_001 xmlns:E24B="urn:E24B_UpdateMachineCards_001" xmlns:f="urn:fields" xmlns:s="urn:segments"  xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
- <s:CntrolArea>
- <s:Bsr>
    
  <s:Verb>Update</s:Verb> 
    
  <s:Noun>Machine Card</s:Noun> 
    
-------------------------------------------------------------

Also xml content need to have multiple namespace. Can you help me please?

Nurhan

Accepted Solutions (1)

Accepted Solutions (1)

Former Member
0 Kudos

Hi Nuhran,

You can use either XSLT or JAVA mapping to add additional namespace

In case of XSLT:

Add the required namespace in the XSLT program and use copy Root node, this will copy the entire message

In case of Java:

Write a java program to consume the file and insert in line number 3 or 4 the required namespace

After that you have your graphical mapping

regards

Ramesh

Former Member
0 Kudos

Hi Nuhran,

I am giving you the sample code. It covers the ControlArea part and rest you need to code it.

<?xml version="1.0" encoding="ISO-8859-1" ?> 
- <!--  Edited by XMLSpy® 
  --> 
- <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:E24B="urn:E24B_UpdateMachineCards_001" xmlns:f="urn:fields" xmlns:s="urn:segments" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
- <xsl:template match="/">
- <E24B:E24B_Update_MachineCards_001>
- <s:ControlArea>
- <s:Bsr>
- <s:Verb>
  <xsl:value-of select="//Verb"></xsl:value-of> 
  </s:Verb>
- <s:Noun>
  <xsl:value-of select="//Noun"></xsl:value-of> 
  </s:Noun>
  </s:Bsr>
- <s:Sender>
- <s:LogicalId>
  <xsl:value-of select="//LogicalId"></xsl:value-of> 
  </s:LogicalId>
- <s:ReferenceId>
  <xsl:value-of select="//ReferenceId"></xsl:value-of> 
  </s:ReferenceId>
  </s:Sender>
- <s:DateTime>
- <s:Dt_Qualifier>
  <xsl:value-of select="//Dt_Qualifier"></xsl:value-of> 
  </s:Dt_Qualifier>
- <s:Dt_Value>
  <xsl:value-of select="//Dt_Value"></xsl:value-of> 
  </s:Dt_Value>
- <s:TimeZone>
  <xsl:value-of select="//TimeZone"></xsl:value-of> 
  </s:TimeZone>
  </s:DateTime>
  </s:ControlArea>
  </E24B:E24B_Update_MachineCards_001>
  </xsl:template>
  </xsl:stylesheet>

****Note: THIS CODE IS FOR YOU TO UNDERSTAND, HOW TO ARRIVE AT REQUIRED OUTPUT. BUT MIGHT NOT PROVIDE YOU FULL AND EFFICIENT RESULT.

Please modify and enhance it according to your requirement

Regards

Ramesh

Former Member
0 Kudos

Thank you very much for your help

Answers (3)

Answers (3)

Former Member
0 Kudos

HI,

Use the XSLT mapping after the message mapping in your operation mapping.

Sample XSLT code is below.

<?xml version="1.0" encoding="ISO-8859-1"?>

<xsl:stylesheet version="1.0"

xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:ns0="http://www.portal.fucapi.in">

<xsl:template match="/">

<lote xmlns="http://www.portal.fucapi.in" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.portal.fucapi.in http://alvaraes.gov.in:7778//jsp/importardados/NF.xsd">;

<xsl:attribute name = "nro">

<xsl:value-of select = "/ns0:lote/@nro"/>

</xsl:attribute>

<xsl:element name="qtdeNF">

<xsl:value-of select = "/ns0:lote/ns0:qtdeNF"/>

</xsl:element>

<notasFiscais>

<xsl:for-each select="/ns0:lote/ns0:notasFiscais/ns0:notaFiscal">

<xsl:copy-of select="/ns0:lote/ns0:notasFiscais/ns0:notaFiscal"/>

</xsl:for-each>

</notasFiscais>

</lote>

</xsl:template>

</xsl:stylesheet>

regards,

ganesh.

PriyankaAnagani
Active Contributor
0 Kudos

Hi,

You can add additional namespaces using java/xslt mapping . Please go through this it may help you.

Regards,

Priyanka

anupam_ghosh2
Active Contributor
0 Kudos

Hi Nurhan,

You need java mapping or XSLT mapping to resolve the issue. Could you please kindly post the complete source XML and exact complete target XML. What is the version of PI you are working on?

Regards

Anupam

Former Member
0 Kudos

I used for target external definition and for prefix (E24B , f , s, instead of ns0, ns1..) i added module "AF_Modules/XMLAnonymizerBean".

My source xml from is



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

<ns0:MT_Machine_Update xmlns:ns0="http://xxx.com/MachineUpdate">
   <ControlArea>
      <Bsr>
         <Verb>13</Verb>
         <Noun>32</Noun>
      </Bsr>
      <Sender>
         <LogicalId>34124</LogicalId>
         <ReferenceId>124</ReferenceId>
      </Sender>
      <DateTime>
         <Dt_Qualifier>42</Dt_Qualifier>
         <Dt_Value>214</Dt_Value>
         <TimeZone>14</TimeZone>
      </DateTime>
   </ControlArea>
   <DataArea>
      <UpdateMachineCards>
         <CompanyCode>4325</CompanyCode>
         <CompanyName>325</CompanyName>
         <ManufacturerCode>352</ManufacturerCode>
         <ManufacturerName>53</ManufacturerName>
         <Machine>
            <SalesModel>24</SalesModel>
            <SerialNo>352</SerialNo>
            <EnvironmentCode>53</EnvironmentCode>
            <Market>
               <FinalMarket>24</FinalMarket>
               <NewCompanyCode></NewCompanyCode>
            </Market>
            <Component>
               <ComponentType>23</ComponentType>
               <PartNo>35</PartNo>
               <Model>35</Model>
               <ComponentSerNo>352</ComponentSerNo>
            </Component>
         </Machine>
      </UpdateMachineCards>
   </DataArea>
</ns0:MT_Machine_Update>

The output should be as follows:


<?xml version="1.0" encoding="UTF-8" ?> 
- <E24B:E24B_Update_MachineCards_001 xmlns:E24B="urn:E24B_UpdateMachineCards_001" xmlns:f="urn:fields" xmlns:s="urn:segments" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
- <s:CntrolArea>
- <s:Bsr>
    
  <s:Verb>Update</s:Verb> 
    
  <s:Noun>Machine Card</s:Noun> 
    
  </s:Bsr>
- <s:Sender>
    
  <s:LogicalId>CWL</s:LogicalId> 
    
  <s:ReferenceId>2006-03-21T12:26:33</s:ReferenceId> 
    
  </s:Sender>
- <s:DateTime>
    
  <s:Dt_Qualifier>Creation</s:Dt_Qualifier> 
    
  <s:Dt_Value>2006-03-24T14:29:46</s:Dt_Value> 
    
  <s:TimeZone>+02:00</s:TimeZone> 
    
  </s:DateTime>
    
  </s:CntrolArea>
- <E24B:DataArea>
- <E24B:UpdateMachineCards>
    
  <f:CompanyCode>428003</f:CompanyCode> 
    
  <f:CompanyName>VOLVO ÉPÍTÕGÉPEK HUNGÁRIA KERESKEDELMI KFT.</f:CompanyName> 
    
  <f:ManufacturerCode>CWL</f:ManufacturerCode> 
    
  <f:ManufacturerName>VOLVO COMPACT W</f:ManufacturerName> 
- <E24B:Machine>
    
  <f:SalesModel>L45</f:SalesModel> 
    
  <f:SerialNo>19521</f:SerialNo> 
    
  <f:CurrentDate>20060323</f:CurrentDate> 
- <E24B:Market>
    
  <f:FinalMarket>HU</f:FinalMarket> 
    
  </E24B:Market>
- <E24B:Component>
    
  <f:ComponentType>17</f:ComponentType> 
    
  <f:PartNo>11305947</f:PartNo> 
    
  <f:ComponentSerNo>G070910121</f:ComponentSerNo> 
    
  </E24B:Component>
- <E24B:Component>
    
  <f:ComponentType>66</f:ComponentType> 
    
  <f:PartNo>2814557</f:PartNo> 
    
  <f:ComponentSerNo>100710021</f:ComponentSerNo> 
    
  </E24B:Component>
    
  </E24B:Machine>
    
  </E24B:UpdateMachineCards>
    
  </E24B:DataArea>
    
  </E24B:E24B_Update_MachineCards_001>

Thanks for your help