开发者

Felxibility of data import/export feature using XML-binding

I am going to develop a database import/export feature in a Java EE application.

I plan to use XML-binding solution to convert between Java object and XML file which is import/export file.

  • Import feature: unmarshal the XML file to Java object in memory representation, then use JDBC to update the database.

  • Export feature: inverse the import process. retrieve the database to Java object and marshal the object to XML.

I think it can work fine, but it's not flexible enough. Because the XSD of XML is pre-defined, it's impossible to change XML schema and Java object definition at runtime. Say it's dynamic binding. Even I want the feature supports other file formats (You could forget it, if the format is too far at this stage).

Wha开发者_如何学Ct is your advice about the feature? Thanks!


I don't know whether this is correct answer, but if in any case it is helpful: I have used Spring, Hibernate, JAXB where you can annotate your database entity class and its element with jaxb annotation and you are not required to write any xml schema files. In spring you can use jaxb Marshaller.

I think it should be possible in pure jaxb also, so u can look into jaxb annotation.


I think it can work fine, but it's not flexible enough. Because the XSD of XML is pre-defined, it's impossible to change XML schema and Java object definition at runtime

If you think it isn't flexible enough, go with a data interchange format which relieves you from all these fixed schema definitions (I know even JSON has a schema specification but you get the point). Is using JSON acceptable?

I would go as far to argue that if "importing to database" and "exporting from database" is the only requirement, you need not even create Java objects for this. Simply pass in a JSON string which contains the schema which would then be processed by a JSON processor which interfaces directly with your DAO layer. Similarly with the data read from the database. The downside is that "date" support in JSON is spotty at best.

Come to think of it, it need not be JSON. You can take a look at other data serialization formats like Apache Avro. But then again, if XML is your requirement which can't be changed, you can get around the "flexibility limitation" by not using a schema at all.

After all, XML is like violence. If it doesn't solve your problem, you're not using enough of it. :-)

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜