I have a table in PosgreSQL.
I have an xml schema.
I want to create an xml document with this schema and data from Postgre.
What should I read to work with xsd in java? And what are the best tools to use?
UPDATE
More specific question. Can i create data base in PostgreSql using xml schema?
UPDATE 2
Okey. I create data base from .xsd using XMLSpy.
Now i need load xml document in this data base. What i gonna do?
UPDATE 3
Okay. I generate java classes using JiBX.
Now i want to read xml file and write data from this to data base. What i gonna do?
Probably best to generate java classes for the XML from the XSD, you can read about it here:
Generate Java classes from .XSD files...?
I dont know anything about the postgreSql, but i will suggest you to generate java classes from your Xsd using jaxb and use those classes as domain for your db.
yes, the best way to accomplish the above task would be to generate java class and populate your respective beans.
From there on you can insert your values of beans to the respective tables in posgresql
Related
I have given a XML file. I want to store a subset of the content of this file in a relational database.
I could use a framework like JAXB to convert the content of the xml file into Java POJOs and write them to database (e.g. with Hibernate).
But is there a built-in opportunity in Hibernate to do this without using a additional framework like JAXB?
Thanks for your help!!
As far as I remember, there was an XML mapping feature in Hibernate 3:
https://docs.jboss.org/hibernate/orm/3.3/reference/en/html/xml.html
However this feature was noted as "experimental". And I don't see it in Hibernate 4 or 5:
https://docs.jboss.org/hibernate/orm/4.1/manual/en-US/html/
http://docs.jboss.org/hibernate/orm/5.0/userGuide/en-US/html_single/
I have a huge xml file. I need to convert the xml into java objects and persist the data in Database. It will be around 200k records. Planning to use jibx. Is it a right approach? If so can someone provide the steps to convert xml file to java objects and persist in database
I just finish a project to convert a huge Xml file. I use trang ( http://www.thaiopensource.com/download/ ) to generate an XSD file from the XML File. Then i use xjc on the xsd file to generate POJO objects then I use JAXB to load the xml file into memory then Hibernate to create the database and store the POJOs.
I need to validate some xml files in the resources of an Android application against an XML Schema. Although there is an available API to create instances of SchemaFactory, there seems to be no implementation for XML Schema, as stated by the answers to these questions: 1, 2 and 3.
Are there any good and lightweight libraries to provide that functionality in the Android platform?
Try Lycia. Its around 270 kb. Here is nice step by step example for schema validation. It creates a schema, a small XML referring to schema (via schemaLocation) and then an example to parse the xml with schema validation
Hibernate can auto-generate schemas from properly annotated POJO classes. And I also know that JIBX can create a data model (set of classes) out of properly structured XML schemas. Is there a way to automaticaly generate annotated-mapped classes from an XML schema? Or is it just possible to run a tool on a set of POJO classes, and expect it to create meaningful annotations on the specified classes? So later on we can create database schemas using these classes. To annotate every class that JIBX produces takes actually more work than manually designing the database schema according to the xml schema.
The Hyperjaxb project will generate JAXB classes from an XML schema that contain JPA annotations that could be used to create a database schema.
http://java.net/projects/hyperjaxb
Nice question! We had the same problem and we ended up developing the POJO generator with Freemarker.
By the way, the requirements to these POJOs may strongly vary, so, if such tool exists, it must have quite bloated configuration.
I have to write a process (in Java) which periodically hits a URL, reads the returned XML document, and persists that data into the DB. This data is further used by my application, so I have modeled them as Hibernate-mapped POJOs.
I can parse the XML and then create appropriate POJOs, but I was looking for a simpler declarative approach. What libraries are available which can take a input configuration and create the POJOs from the XML document?
Another alternative could be JiBX
Also, although you said you don't want to parse the XML, XPath can be a very concise way of extracting the content you are interested in?
JAXB can automatically create classes based on an XML Schema (assuming you have one for the XML source). At runtime, it can then convert the XML document into POJOs representing the XML. It is declarative in that you can tweak the Schema-to-class mapping, a little.
If I understand your task correctly, this is pretty much the use-case JAXB was designed for (though it can do other things too). It's part of Java 1.6 (maybe 1.5 too?), in packages: javax.xml.bind.*
You can use XStream to deserialize the XML and map it directly to the Hibernate-mapped POJOs.
Cheers.
Using Hibernate you can directly map XML to table. This is experimental feature. Check here
http://www.hibernate.org/hib_docs/v3/reference/en-US/html/xml.html
EclipseLink JAXB (MOXy) has extensions for mapping JPA entities to XML (JPA entities have things like embedded ID classes, lazy loading, and compound key relationships that need special handling), I'm not aware of any other OXM solution that does this.
For more information see:
http://wiki.eclipse.org/EclipseLink/Examples/MOXy/JPA