• Index
  •  » Talend Open Studio for Data Integration » Usage, Operation
  •  » inserting an xml into another xml

#1 2009-08-27 04:36:07

mbernaza
New member
Registered: 2009-08-27
Posts: 3

inserting an xml into another xml

Tags: [append, insert, xml]

Hello

Could some one could help me with this issue, please
Env Windows Xp , TOS 3.0 generate to Java
Because tAdavanceFileOutpuXML does not support multiple loops I created two xml files that I need to insert one into another one.



xml 1

  <CustomerInvoices>
    <CustomerInvoice>
      <InvoiceHeader>
        <RefNumber>6004</RefNumber>
        <Date>25-08-2009</Date>
        <CreationDateTime>25-08-2009</CreationDateTime>
        <Currency>EUR</Currency>
        <Booking>
          <BookingID>2004</BookingID>
          <TotalAmount>100</TotalAmount>
        </Booking>
      </InvoiceHeader>
      <invoiceItems>
        <invoiceItem>
          <SeqNumber>6007</SeqNumber>
          <BookingFinancialTransaction>
            <BookingFinancTransRef>107</BookingFinancTransRef>
            <NbPassenger>0</NbPassenger>
          </BookingFinancialTransaction>
        </invoiceItem>
      </invoiceItems>
   </CustomerInvoice>
</CustomerInvoices>

xml 2

<CustomerInvoice>
  <RefNumber>6001</RefNumber>
  <Booking>
    <BookingID>2004</BookingID>
    <BookingContextAxisList>
      <Context>
        <ContextName>CUSTOMER_MARKET</ContextName>
        <Value>CASSURA</Value>
      </Context>
      <Context>
        <ContextName>CUSTOMER_MARKET</ContextName>
        <Value>FR</Value>
      </Context>
    </BookingContextAxisList>
  </Booking>
  <Booking>
</CustomerInvoice>



The expected result will be like this

  <CustomerInvoices>
    <CustomerInvoice>
      <InvoiceHeader>
        <RefNumber>6004</RefNumber>
        <Date>25-08-2009</Date>
        <CreationDateTime>25-08-2009</CreationDateTime>
        <Currency>EUR</Currency>
        <Booking>
          <BookingID>2004</BookingID>
          <TotalAmount>100</TotalAmount>
          <BookingContextAxisList>
            <Context>
               <ContextName>CUSTOMER_MARKET</ContextName>
               <Value>CASSURA</Value>
           </Context>
           <Context>
             <ContextName>CUSTOMER_MARKET</ContextName>
             <Value>FR</Value>
           </Context>
        </BookingContextAxisList>
   </Booking>
      </InvoiceHeader>
      <invoiceItems>
        <invoiceItem>
          <SeqNumber>6007</SeqNumber>
          <BookingFinancialTransaction>
            <BookingFinancTransRef>107</BookingFinancTransRef>
            <NbPassenger>0</NbPassenger>
          </BookingFinancialTransaction>
        </invoiceItem>
      </invoiceItems>
   </CustomerInvoice>
</CustomerInvoices>


Thanks in advance

Last edited by mbernaza (2009-08-27 04:48:09)

Offline

#2 2009-08-27 05:10:13

shong
Talend team
Registered: 2007-08-29
Posts: 10294
Website

Re: inserting an xml into another xml

Hello
You can use the 'Append the source xml file' feature on tAdvancedFileoutputXML, here I extract records fron xml 2 and insert them into xml 1. Please see my screenshots.
result:

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

<CustomerInvoices>
  <CustomerInvoice>
    <InvoiceHeader>
      <RefNumber>6004</RefNumber> 
      <Date>25-08-2009</Date> 
      <CreationDateTime>25-08-2009</CreationDateTime> 
      <Currency>EUR</Currency> 
      <Booking>
        <BookingID>2004</BookingID> 
        <TotalAmount>100</TotalAmount> 
        <BookingContextAxisList>
          <Context>
            <ContextName>CUSTOMER_MARKET</ContextName>
            <Value>CASSURA</Value>
          </Context>
          <Context>
            <ContextName>CUSTOMER_MARKET</ContextName>
            <Value>FR</Value>
          </Context>
        </BookingContextAxisList>
      </Booking>
    </InvoiceHeader> 
    <invoiceItems>
      <invoiceItem>
        <SeqNumber>6007</SeqNumber> 
        <BookingFinancialTransaction>
          <BookingFinancTransRef>107</BookingFinancTransRef> 
          <NbPassenger>0</NbPassenger>
        </BookingFinancialTransaction>
      </invoiceItem>
    </invoiceItems>
  </CustomerInvoice>
</CustomerInvoices>


Best regards

         shong


Uploaded Images


Email:shong@talend.com
Choose Talend, Enjoy Talend!
New & Event: Talend Help Center
Talend-->the leader of open source data management and application integration solutions!

Offline

#3 2009-08-27 16:07:50

mbernaza
New member
Registered: 2009-08-27
Posts: 3

Re: inserting an xml into another xml

Thanks a lot Shong

I have the xml1 and xml 2 in two independents  tAdavanceFileOutputXML, could you please let me know how to design the flow to arrive to your proposition.

Regards

Offline

#4 2009-08-27 21:22:33

mbernaza
New member
Registered: 2009-08-27
Posts: 3

Re: inserting an xml into another xml

Hello Shong

Sorry , maybe I didnt mentioned properly.

the xml 2 is like this

<CustomerInvoice>
    <Booking>
    <BookingID>2004</BookingID>
    <BookingContextAxisList>
      <Context>
        <ContextName>CUSTOMER_MARKET</ContextName>
        <Value>CASSURA</Value>
      </Context>
      <Context>
        <ContextName>CUSTOMER_MARKET</ContextName>
        <Value>FR</Value>
      </Context>
    </BookingContextAxisList>
  </Booking>
  <Booking>
  <Booking>
    <BookingID>2008</BookingID>
    <BookingContextAxisList>
      <Context>
        <ContextName>CUSTOMER_MARKET</ContextName>
        <Value>VALUE FOR BOOK 2008</Value>
      </Context>
      <Context>
        <ContextName>CUSTOMER_MARKET</ContextName>
        <Value>EN</Value>
      </Context>
    </BookingContextAxisList>
  </Booking>
</CustomerInvoice>


I tried your recomendation, but the result is that the xml 2 was inserted completly in the first appear . What I need is to insert the BookingContextAxisList of each booking to his corresponding Booking in XML 1

Offline

#5 2009-08-28 07:27:26

shong
Talend team
Registered: 2007-08-29
Posts: 10294
Website

Re: inserting an xml into another xml

Hello
Aslo extract the booking id from xlm2, and then set booking element as group element.

Best regards
   
         shong


Uploaded Images


Email:shong@talend.com
Choose Talend, Enjoy Talend!
New & Event: Talend Help Center
Talend-->the leader of open source data management and application integration solutions!

Offline

#6 2011-08-16 01:29:55

roboaks1
Member
Company: ITS Data Services
Registered: 2011-06-17
Posts: 31

Re: inserting an xml into another xml

shong wrote:

Hello
Aslo extract the booking id from xlm2, and then set booking element as group element.

Best regards
   
         shong

mbernaza: Did this solution work? The ability to construct a complex, hierarchical XML document from a DB flow is critical for us. Would another approach be more robust, such as using tJavaRow, and leveraging either the DOM or, easier still, a Java XML data binding tool (Castor, JAXB, Liquid Tech's, etc.).


Rob Oaks
ITS Data Services

Offline

  • Index
  •  » Talend Open Studio for Data Integration » Usage, Operation
  •  » inserting an xml into another xml

Board footer

Powered by FluxBB