Most relational databases have mechanisms to converting SQL query results into XML.
Look at IBMs XML Extender, Oracles XSQL templates and the FOR XML support in Microsoft's SQLServer (which offers a very comprehensive relational<>XML support).
I would recommend that you either use the one that fits with the database that you already use or compare the above and chose the one fitting your need.
Disclaimer: I am obviously biased
Program Manager, SQL Server XML Technologies
We store the Web and more...