tags:

views:

155

answers:

7

how can i convert xml to java so that it could read the xml document and put it in to a database?

+1  A: 

Check this: http://www.java-tips.org/java-se-tips/javax.xml.parsers/how-to-read-xml-file-in-java.html That's how you read xml file. Then you just crate SQL query to insert it into database (JDBC?)

Maksim
great this is what im looking for now i want to know how do i create the sql database
matt
here you go: http://www.vogella.de/articles/MySQLJava/article.html
Maksim
thanks for the info
matt
+5  A: 

Your question is rather obscure and general. There are a number of options for converting XML to Java objects:

This article could be useful.

But anyway you will have to read much before getting something more complex to work.

This is all in case you need to map your xml to java objects. If you just need to parse the XML:

Bozho
A: 

Apparently JAXB can do marshalling/unmarshalling. I've not used it, but it seems to do what you want. From there, you can use an ORM of some type to put your objects in a database, or you can handcraft SQL.

Stefan Kendall
A: 

It sounds like you are looking for something like JAXB or Castor. They both let you convert from a Java object -> XML and XML -> Java object.

Taylor Leese
A: 

It's not clear at all, but if you are talking about parsing a XML file to do whatever you want with it in Java (also storing it in a database) you have to already ready choices:

  • using a DOM parser
  • using a SAX parser

both are covered here just to give you an example, but check documentation for better explaination.

Jack
A: 

Check Hyperjaxb3. It is a JAXB plugin which makes schema-derived classes to JPA entities. Thus you can easily do XML <-(JAXB)-> Java <-(JPA)-> RDB.

lexicore
A: 

For this I recommend EclipseLink. EclipseLink offers both JAXB (object-to-XML) and JPA (object-to-Database) support.

The EclipseLink JAXB (MOXy) implementation offers all the extensions you need for mapping JPA entities to XML, for more information see:

Blaise Doughan