matt
matt

Reputation: 1631

Convert xml to java

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

Upvotes: 1

Views: 615

Answers (8)

Hilal
Hilal

Reputation: 111

Use this https://json2csharp.com/xml-to-java in case you're looking for an online tool, you can then deserialize your object and fill it in the database

Upvotes: 0

bdoughan
bdoughan

Reputation: 149047

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:

Upvotes: 0

lexicore
lexicore

Reputation: 43709

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.

Upvotes: 0

Jack
Jack

Reputation: 133669

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.

Upvotes: 1

Taylor Leese
Taylor Leese

Reputation: 52400

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.

Upvotes: 0

Stefan Kendall
Stefan Kendall

Reputation: 67892

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.

Upvotes: 0

Bozho
Bozho

Reputation: 597402

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:

Upvotes: 6

Maksim
Maksim

Reputation: 16941

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?)

Upvotes: 1

Related Questions