aspose file tools*
The moose likes XML and Related Technologies and the fly likes XML/XSD to Database using Java Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of EJB 3 in Action this week in the EJB and other Java EE Technologies forum!
JavaRanch » Java Forums » Engineering » XML and Related Technologies
Bookmark "XML/XSD to Database using Java" Watch "XML/XSD to Database using Java" New topic
Author

XML/XSD to Database using Java

yatin naik
Greenhorn

Joined: Feb 08, 2010
Posts: 1
Hi,
I have an XSD schema and associated XML file that i need to parse for all the elements and store it in our database. This XML will be updated on a daily basis.

I need suggestions on how to go about creating db tables from the XSD (if there are any tools available) and suggestions on the Java API to use for binding the XML data to the db tables. Since the XML file is very large, i don't want to write manual DOM code for parsing every element and inserting it in the database.

Thanks in advance....
Marco Ehrentreich
best scout
Bartender

Joined: Mar 07, 2007
Posts: 1278

Hi Yatin,

welcome to the JavaRanch

It depends on the size of this project if it's worth the effort, but if your schema doesn't change too often one possible, more or less elegant solution could be to use JAXB which can help to create a complete Java object model to represent possible XML document in memory (but with typed classes for each node instead of generic DOM elements) and marshal/unmarshal to and from XML.

Additionally you could annotate this same class/object model to use JPA as O/R mapper which in turn can auto-generate the database schema from this object model an persist a unmarshalled XML document directly into a relational database.

If the schema changes you would have to step through the auto-generation process or modify the class model by hand. But on the other hand you would most probably have to do adapt your application with other solutions as well after a change to the schema.

Marco
Velu Kasirajah
Greenhorn

Joined: Feb 06, 2010
Posts: 15
You can also try Apache XMLBeans for parsing your XML data and creating Java objects. If shredding the data is not required, then you can also think about just dumping it as a BLOB.


Velu Kasirajah
Marco Ehrentreich
best scout
Bartender

Joined: Mar 07, 2007
Posts: 1278

Writing the XML content or serialized object graph as a BLOB into the database would be the easiest solution of course. Just be aware that this could have negative effects on the application performance if the content is really big because you would always have to read/write the whole bunch of XML. Also you can't easily use database operations to query or modify the data inside the BLOB. This may not be an issue depending on your requirements, but take the time to think about it carefully.

Marco
Velu Kasirajah
Greenhorn

Joined: Feb 06, 2010
Posts: 15
Yes. If there's any need to query the XML data based on certain criteria, then do the required level of shredding before putting it into the database. This will make it easier to query and retrieve the data.
 
Consider Paul's rocket mass heater.
 
subject: XML/XSD to Database using Java
 
Similar Threads
Best Method to Read XML Schema
HR-XML
Create a XML file in Java
How to create a jar file of a java project that uses Derby database
How to read from XSD generated database and put that data into XML file.