Skip to Content
0
Apr 22, 2009 at 03:42 PM

Split many elements in others many elements

55 Views

Hi folks.

I have to follow source XML to map to receiver XML:

source
....
<SERVICE>
  <SRVNR>1001</SRVNR>
  <MATERIAL>
    <MATNR>QWERT</MATNR>
  </MATERIAL>
  <MATERIAL>
    <MATNR>ASDFG</MATNR>
  </MATERIAL>
</SERVICE>
<SERVICE>
  <SRVNR>2002</SRVNR>
</SERVICE>
<SERVICE>
  <SRVNR>3003</SRVNR>
  <MATERIAL>
    <MATNR>ZXCVB</MATNR>
  </MATERIAL>
</SERVICE>
....

receiver must be as follow
....
<MATERIAL>
  <SRVNR>1001</SRVNR>
  <MATNR>QWERT</MATNR>
</MATERIAL>
<MATERIAL>
  <SRVNR>1001</SRVNR>
  <MATNR>ASDFG</MATNR>
</MATERIAL>
<MATERIAL>
  <SRVNR>3003</SRVNR>
  <MATNR>ZXCVB</MATNR>
</MATERIAL>
....

but the result is below
<MATERIAL>
  <SRVNR>1001</SRVNR>
  <MATNR>QWERT</MATNR>
</MATERIAL>
<MATERIAL>
  <SRVNR>2002</SRVNR>
  <MATNR>ASDFG</MATNR>
</MATERIAL>
<MATERIAL>
  <SRVNR>3003</SRVNR>
  <MATNR>ZXCVB</MATNR>
</MATERIAL>

I've tried the code below:

 for (int i=0; i<a.length;i++){
  result.addValue(b[0]);
}

where the parameter a is my root <MATERIAL> and the parameter b is element <SRVNR>, but the result is wrong.

I've tried node function useOneAsMany but doesn't work too.

My difficult is associate root <SERVER> with corresponding roots <MATERIAL> in the result using either a node function or an user define function.

Someone can help me, please?

Thanks in advanced.