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



Solution 1:[1]

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

Solution 2:[2]

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:

Solution 3:[3]

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.

Solution 4:[4]

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.

Solution 5:[5]

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.

Solution 6:[6]

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.

Solution 7:[7]

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:

Solution 8:[8]

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

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Maksim
Solution 2 Bozho
Solution 3 Jack
Solution 4 Stefan Kendall
Solution 5 Taylor Leese
Solution 6 lexicore
Solution 7
Solution 8 Hilal