使用 JAXB 2.x 基于 XSD 在运行时解析 XML
有一个需求,所以想检查其可行性。我们正在使用 JAXB 2.x 将 XML 解组为现有的 POJO 类。下面是我们正在遵循的过程。
- 基于 XSD,我们已经使用 JAXB 实用程序创建了所需的类。
- 在运行时,我们仅传递 XML 文件,并且首先使用预先存在的 XSD 验证 XML,如果成功,将继续进行解组。
- 对于 XML 创建,过程相同,但顺序相反。
现在有一个要求,因此客户端希望他们可以将 XML 和 XSD 传递给正在开发的方法,并且该方法应该通过解析该 XML 将公共对象作为返回移交,稍后他们将处理将该通用对象映射为具体课程。
我的问题是,在 Jaxb 2.x 中是否有可能根据提供的 XSD 首先动态创建所需的类,然后解析 XML 并将结果移交给客户端模块,以便他们可以完成映射工作或者是有什么办法可以实现该功能吗?
提前致谢
Have a requirement so want to 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..
- Based on the XSD provided we have already created required classes using JAXB utility.
- 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.
- 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
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
在 EclipseLink MOXy(我是技术主管)中,我们有一个称为 Dynamic JAXB 的功能,它允许您从 XML 模式引导并使用通用对象。您可能会发现这种方法很有用:
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:
我知道这是可行的。我实验室的一名学生在不同的主题上做了几乎相同的事情。不过,您必须使用类加载器才能动态加载您开玩笑创建的类。完成后,您可以使用包含新类的类加载器来解析 XML。
当然,这并不像听起来那么容易......
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...
看看示例samples/inline-customize
位于 http://download.oracle .com/docs/cd/E17802_01/webservices/webservices/docs/2.0/jaxb/samples.html
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