tags:

views:

97

answers:

3

Does anyone know good XML library for Java which I can use to write data extracted from database into XML format?

+3  A: 

Usually, those tools are already provided by the database itself. Check the "Export" section somewhere in their documentation. A more detailed answer can't be given since the DB vendor is unmentioned.

Regardless, if you insist in using Java for this (which may however be performance/memory hogging with large data), then you may find a Javabean-to-XML serializer useful, for example JAXB, XStream or XMLBeans.

BalusC
+1; the OP would be well-served to not reinvent this particular wheel. :-)
BlairHippo
Thanks , but the data I need to extract from database is not from a single table , but multiple and with custom formatting.
yogsma
You should mention JAXB it comes with java 1.6
Justin
@BalusC - I understand. There is much more to this ..harmonization of data won't happen in SQL , I need to do that in my code before transforming into XML.
yogsma
@yogsma: aren't you undervaluing SQL? Joins? Functions? Procedures? The average DB is undoubtely much more efficient in this job. In Java you would need to get hold of all the data in memory and then preferably need 2~5 times more free space in the memory than the data actually large is, else you will face constantly `OutOfMemoryErrors`. I would still consult some SQL Ninja (or ask here) if it is really, *really* not possible in pure SQL. Just to be sure.
BalusC
@BalusC - Thanks, let me figure this out little bit , else I will ask the question for sure.
yogsma
+2  A: 

JAXB all you need to do is annotate a class and you can marshal it to XML. Works well with JPA entities / other ORMs as well.

Justin
+1, also the MOXy implmentation of JAXB has a number of extensions for dealing with JPA entities http://wiki.eclipse.org/EclipseLink/Examples/MOXy/JPA
Blaise Doughan
+1  A: 

Do you need to use a middle layer? "Most" DBMS have some XML functionality out of the box, like MySQL.

mysql -uroot --xml -e 'SELECT * FROM db.table ORDER BY field'
Björn