简体   繁体   中英

Convert records in database to XML in mule

I'm a newbie to mule and I'm trying to create an XML based on the data, loaded from a DB. It's easy to create an XML from a single table but what about when the query uses joins ?

select * from customer c 
left join address a
on c.id=u.customer_fk;

Such a query returns a product

--customer_name;customer_id,street,number,addr_id,customer_fk
customer1;1;fleet street;1A;1;1
customer1;1;baker street;221b;2;1
customer2;2;bond street;33;3;2
etc...

The XML I want to create should look like this:

<customer>
  <id>1</id>
  <name>customer1</name>
  <address>      
     <street>fleet street</street>
     <number>1A</number> 
     <addr_id>1</addr_id>
     <customer_fk>1</customer_fk>
  </address>
  <address>      
     <street>baker street</street>
     <number>221b</number> 
     <addr_id>2</addr_id>
     <customer_fk>1</customer_fk>
  </address>
</customer>
<customer>
  <id>2</id>
  <name>customer2</name>
  <address>      
     <street>bond street</street>
     <number>33</number> 
     <addr_id>3</addr_id>
     <customer_fk>2</customer_fk>
  </address>
</customer>

Can you give me some advice on how to transform the database resultset to be able to construct such XML ?

thanks!

Could you provide an example of how the data is returned following the query to the database? (Perhaps an example payload).

Otherwise, first thoughts on approaching this would be to use the Maps-to-XML transformer (if the DB output is maps) or DataMapper component.

FYI - both of these require an Enterprise Edition of Mule.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM