XML : Java : Working with multiple versions of XML Schemas

I have an application that receives an XML message and then parses it to perform further processing.In order to have this working in my application, after receiving the XML string, I call the JAXB marshaller to marshal it in to java POJOs and the processing takes from here after. This thing works well till the time I have one version of XML.

Problem But the problem comes when there are more than one versions of the same XSD. And my application has to deal with both version of messages. Clients to my application may send a old version xml or they may send a latest version XML.

For JAXB I have to convert the XSD into java pojos using JAVA XJC tool, and the problem arises when I convert the latest version of XSD it has the same class names as the previous version, but internal fields and hierarchy of the class is different. this causes problems even if i put the XJC outputs in different jars for each version.

Expected Solution This change in version is expected to happen every 6 months and I have to make my system able to read the newer version XMLs also alongwith the old versions. I want to know how to manage this XML processing in JAVA with JAXB or some other framework.

Shall I use SAX Parser? I have read that its not that efficient as compared to JAXB. And after working on SAX parser for last few days, i found out that it can be error prone as it involves looking for each element and getting values out of it and putting it into a java structure of our own and that is a lot of effort as compared to JAXB.

* Question

Is there any simple solution similar like JAXB ?

*

Temporary Solution Used I have used a temporary solution, with which i am not happy as a good solution. What I did is, I created a seperate jar for each XSD version using XJC tool. And created different packages ion each jar e.g. 1. Pojos for version 1.2 are in a jar with base package com.cgs.v_12 2. Pojos for version 2.0 are in a different jar with base package com.cgs.v_20

i have added both as a maven dependancy to my system and using them for processing different versions.

No comments:

Post a Comment