I need to export some data from a DB to a XML file but I've never worked with XML in Java so I need your help. First of all, what is the best thecnology to use? I've seen JAXB, SAX, DOM and some others, but I don't know where to start here and what will be the best one to use.
In order to create the XML, I must follow the rules from a xsd file and the created XML will have several sections created, each of the sections being retrieved from a different table/tables.
SAX is not suitable to create XML document as it doesn't allow manipulation of data in memory.
JAXB and DOM are useful to create XML documents. Building XML document using DOM API requires understanding the document tree structure and adding child nodes one after one which may be tedious.
JAXB API can be used to convert XML document into Java objects and vice versa. You can generate Java objects from xsd using binding compiler xjc provided by JAXB and load the Java objects with the data from database. Convert the objects into xml using JAXB API.
Typically, the "best" option for creating XML-based data files is to stay away from any "public" API such as DOM, SAX, JAXB, and create a custom API which is specific to the target markup language. Note that this applies for creating complex XML-based structures, not simple structures. Either DOM or JAXB can easily be used for the simple stuff
This option gives you the most degree of control and helps you avoid tightly coupling your code to a specific XML schema, i.e. do not attempt to use schema for "creating" XML-based files.