In this example, an XML document contains nodes representing filenames that aren't known in advance: APIUSER.INI, CISConsis.ini, CLAIM.INI.
<ROW FieldName="FILEPATH" Value="c:\API\BENCH\CWDATA.DAT"/>
<ROW FieldName="ServerIP" Value="192.168.0.1"/>
<ROW FieldName="ServerPort" Value="999999"/>
<ROW FieldName="Drive Letter" Value="a:"/>
Define the Loop
The first step to process this file with Talend Open Studio is to define the loop. In this case, the innermost element 'ROW' will provide me with establish the granularity. I expect each of the four ROW elements to generate a record in the main flow of a job.
The attributes in the ROW element, FieldName and Value are mapped using a single attribute selector.
|Job Processing File with Unknown XML Elements|
The parent elements -- Section, APIUSER.ini, etc. -- give the ROW element context and help differentiate one part's ROW from another's. Section Name is mapped using an attribute selector, but with a parent reference (the relative ../). Section Name will appear in each of the ROWS. Since there are only three section for four elements, one of the Section Names will be repeated.
Mapping the Unknown XML
APIUSER, Cisconsis, and CLAIM are not known in advance, but they can be mapped using the same relative technique used for Section. However, they will require the XPath function name() to provide actual data, since there is no identifying Name element the way there is with Section.
Running the job produces the following four-record result set.
|Output with Filename and Section Repeating Groups|