Six Stars

How to create webservice XML output with embedded loops

Hi, all!

I have a web service that accepts XML data consisting of the TransactionHeader and EmployeeGet sections. TransactionHeader is cut out by tXMLMap1 and goes unchanged into the result, and the EmployeeGet  is passed as a parameter for querying the databases. The databases return the employee tables and their roles, which are linked by the tMap. One employee may have multiple roles.

wa_ws.jpg

Before tXMLMap3 i have  TrasactionHeader rows and Employee data rows (Name, SecondName, RoleNumber) for example:

   Adam, Smith, 2

  John, Bolton, 3

  Mary, Stark, 3

  Mary, Stark, 2

Result must be:

 

        <TransactionHeader xmlns="http://wa.dms.webservice/EmployeeGetRequest">
               SomeHeaderData
           </TransactionHeader>
            <Employees xmlns="http://wa.dms.webservice/EmployeeGetRequest">
               <Employee>
                   <LastName>Smith</LastName>
                   <FirstName>Adam</FirstName>
                  <Roles>
                     <Role>
                        <RoleName>2</RoleName>
                     </Role>
                  </Roles>
               </Employee>
              <Employee>
                   <LastName>Bolton</LastName>
                   <FirstName>John</FirstName>
                  <Roles>
                     <Role>
                        <RoleName>3</RoleName>
                     </Role>
                  </Roles>
               </Employee>
              <Employee>
                   <LastName>Stark</LastName>
                   <FirstName>Mary</FirstName>
                  <Roles>
                     <Role>
                        <RoleName>3</RoleName>
                     </Role>
                     <Role>
                        <RoleName>2</RoleName>
                     </Role>

                  </Roles>
               </Employee>
            </Employees>

How do I configure the tXMLMmap3 to get this result? Where to put loop?

 

When i set loop to <Employee> i got duplicate records for Mary Stark.

When i set loop to <Role> i got just one record <Employee> and many roles such as

       <Employees xmlns="http://wa.dms.webservice/EmployeeGetRequest">
               <Employee>
                   <LastName>Smith</LastName>
                   <FirstName>Adam</FirstName>
                  <Roles>
                     <Role>
                        <RoleName>2</RoleName>
                     </Role>
                      <Role>
                        <RoleName>3</RoleName>
                     </Role>
                     <Role>
                        <RoleName>3</RoleName>
                     </Role>
                     <Role>
                        <RoleName>2</RoleName>
                     </Role>

                  </Roles>
               </Employee>
            </Employees>

 

Tags (3)
1 REPLY
Community Manager

Re: How to create webservice XML output with embedded loops

Hi
Employee should be a group element. Right click on Employee node and select 'As group element' option in the output table of tXMLMap3.

Regards
Shong
----------------------------------------------------------
Talend | Data Agility for Modern Business