darma teja

darma teja

  • NA
  • 496
  • 329.4k

duplicate nodes based on specific nodes in XML

Aug 17 2016 7:43 AM
my XML file is like this:
<root>
   <node1>
      <texts>
              <text>
                  <type>type1</type>
                  <pro1>India</pro1>
                  <pro2>US</pro2>
                  <finalText><![CDATA[XXXXXXXXXX]]></finalText>
            </text>
         <text>
               <type>type2</type>
               <pro1>India</pro1>
               <pro2>US</pro2>
                 <finalText><![CDATA[YYYYYYYYYY]]></finalText>
         </text>
   </texts>
   <texts>
      <text>
            <type>type3</type>
            <pro1>India</pro1>
            <pro2>US</pro2>
            <finalText><![CDATA[XXXXXXXXXX]]></finalText>
      </text>
      <text>
         <type>type4</type>
         <pro1>India</pro1>
         <pro2>US</pro2>
         <finalText><![CDATA[YYYYYYYYYY]]></finalText>
      </text>
</texts>
</node1>
</root>
I want to duplicate the "text" node for every "pro1" and "pro2" nodes:
The output should be like this:
<root>
<node1>
   <texts>
         <text>
               <type>type1</type>
               <pro1>India</pro1>
               <finalText><![CDATA[XXXXXXXXXX]]></finalText>
         </text>
         <text>
               <type>type1</type>
               <pro2>US</pro2>
               <finalText><![CDATA[XXXXXXXXXX]]></finalText>
         </text>
         <text>
               <type>type2</type>
               <pro1>India</pro1>
               <finalText><![CDATA[YYYYYYYYYY]]></finalText>
         </text>
         <text>
               <type>type2</type>
               <pro2>US</pro2>
               <finalText><![CDATA[YYYYYYYYYY]]></finalText>
         </text>
   </texts>
         <texts>
               <text>
                        <type>type3</type>
                        <pro1>India</pro1>
                        <finalText><![CDATA[XXXXXXXXXXyyyyy]]></finalText>
               </text>
               <text>
                        <type>type3</type>
                        <pro1>US</pro1>
                     <finalText><![CDATA[XXXXXXXXXXyyyyy]]></finalText>
            </text>
            <text>
                       <type>type4</type>
                     <pro1>India</pro1>
                     <finalText><![CDATA[zzzzzYYYYYYYYYY]]></finalText>
            </text>
            <text>
                        <type>type4</type>
                         <pro2>US</pro2>
                         <finalText><![CDATA[zzzzzYYYYYYYYYY]]></finalText>
                  </text>
           </texts>
</node1>
</root>
 
Advance thanks,
Darma 

Answers (3)