The following example is based on a simple relational structure where a Company table has a one-to-many relationship with a Contact table. A Contact must refer to just one other Company. This is realized in a Company Id kept on the Contact table.
Company and Contact Tables |
<companies>
<company companyName="HUXLEY INDUSTRIES, INC.">
<contacts>
<contact firstName="David" lastName="King"/>
<contact firstName="Sybil" lastName="Bedford"/>
</contacts>
</company>
<company companyName="SWAN CONSTRUCTION CO.">
<contacts>
<contact firstName="Jocelyn" lastName="Brooke"/>
</contacts>
</company>
<company companyName="CLASSICS PRODUCTION, LLC.">
<contacts>
<contact firstName="Stephen" lastName="Spender"/>
</contacts>
</company>
<company companyName="NOVEL ENTERTAINMENT">
<contacts>
<contact firstName="Lee" lastName="Bartlet"/>
</contacts>
</company>
</companies>
The companies element is repeated, as is the contacts element.
To process the XML, start with an XML schema (XSD). This link points to an XSD created using the Venitian Blind technique. This produces a single top-level element (companies) with reusable types. All other elements (company, contacts, contact) are nested within type definitions.
Start with a job that joins the source tables and writes the output to a tAdvancedFileOutputXML
Talend RDBMS to XML Job |
Metadata from companies.xsd and Added Items |
Right mouse-click over the contact item and "Set as Loop Element". On the company and contacts item, select "Set as Group Element". This defines the repeating groups within the XML document and turns the normalized join into a nested structure.
Next, use a tMap to map the source RDBMS fields to the fields created from the XML metadata. Note the FirstName field will render a firstName XML attribute.
RDBMS Mapping to Target XML |
Good day Carl,
ReplyDeletedo you have this article available as a Talend project?
I am new to Talend and trying to build a similar XML structure (Multiple Accounts with multiple transaction of a financial statement). Everything seems to work up to the point of my tMap (getting 0 merged out with 9 input accounts and 190 transaction inputs)
thank-you
Hi,
DeleteI don't have this particular job anymore. It sounds like you have a problem linking a Transaction to an Account. Break this down by making sure that you can produce a Transaction flow and that the Account IDs look good (Transaction input -> tLogRow). Do the same with the Account (Account input -> tLogRow). Then, link the two together with the tMap (Transaction and Account inputs -> tMap -> tLogRow). Hopefully you can find the problem and get the 190 records out.
Good luck