How can I convert xml to java so that it could read th开发者_如何学Pythone xml document and put it in to a database?
Your question is rather obscure and general. There are a number of options for converting XML to Java objects:
- JAXB
- XStream
- XMLBeans
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:
- dom4j
- xerces
- JAXP
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?)
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.
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.
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.
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.
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:
- http://wiki.eclipse.org/EclipseLink/Examples/MOXy/JPA
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
精彩评论