开发者

Parsing XML at RunTime based on XSD with JAXB 2.x

Have a requirement so want to开发者_JAVA百科 check its feasibility.We are using JAXB 2.x for unmarshling XML in to out existing POJO classes.below is the process we are following..

  1. Based on the XSD provided we have already created required classes using JAXB utility.
  2. On Run time we are passing only XML file and we first validating the XML with the preexisting XSD and if success than will move ahead with the Unmarshling.
  3. For XML creation same process but in reverse order.

Now there is one requirement so the client want that they can pass XML and XSD to the method being developed and this method should hand over the common object as return by parsing that XML and later on they will handle the process of mapping that generic Object with the specific classes.

My question is,Is it possible in Jaxb 2.x that based on the XSD supplied it will first create required classes on the fly and than will parse XML and hand over the result to the client module so they can do the mapping work or is there any way to achieve that functionality??

Thanks in advance


In EclipseLink MOXy (I'm the tech lead) we have a feature called Dynamic JAXB, that lets you bootstrap from an XML schema and use generic objects. You might find this approach useful:

  • http://wiki.eclipse.org/EclipseLink/Examples/MOXy/Dynamic
  • Dynamic java bean from xsd


I know it Is doable. One student in my lab did almost the same thing on a different subject. Though, you will have to play with classloader to be able to load dynamically the classes you've jest created. Once that is done, you can parse the XML using the classloader that includes the new classes.

Of course, it is not as easy as it sounds like...


Have a look at the sample samples/inline-customize located at http://download.oracle.com/docs/cd/E17802_01/webservices/webservices/docs/2.0/jaxb/samples.html

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜