本文介绍了XML到Java映射工具 - 带有映射描述符的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图找到一个允许我将XML的内容放入JavaBean(比如Digester,Jaxb,JIXB等)的库,但我需要它是运行时(不是在编译时,或是通过字节代码)生成)并使用某种映射文件。

I am trying to find a library that allows me to place the content of an XML into a JavaBean (something like Digester, Jaxb, JIXB etc) but I need it to be runtime (not at compile time, or by byte code generation) and use a mapping file of some sort.

这个想法将类似于Hibernate的HBM映射文件,这是一种指定哪个XML元素进入哪个Java属性的方法。我目前正在使用Digester,但我想要一些更简单的规则文件。

The idea will be something like Hibernate's HBM mapping files, a way to specify which XML element goes into which Java property. I am currently using Digester but I want something simpler for its rules file.

这也应该适用于1.4 JDK,因此注释不会真正起作用(但我会考虑这些响应只是为了完整性)。

This should also work on a 1.4 JDK so annotations won't really do (but I will consider such responses just for completeness's sake).

要继续,我需要一个运行时工具,它基于某种类型的XML描述符执行XML到Java,类似于此(取自JIXB)但在运行时(即传递XML,Java) class to output object和mapping descriptor):

To resume, I need a runtime tool that does XML to Java based on a XML descriptor of some sort, something like this (taken from JIXB) but at runtime (i.e. pass it the XML, the Java class to output object and the mapping descriptor):

你知道这样的图书馆吗?

Do you know of such a library?

谢谢!

推荐答案

尝试使用Castor。它能够从DTD生成java代码(也可能从XSD生成)。因此,您可以在运行时生成代码然后进行编译。

Try Castor. It is able to generate java code from DTD (and probably from XSD too). So, you can generate the code at runtime and then compile it.

BTW再次检查JAXB。我相信它也可以这样做。

BTW check JAXB again. I believe that it can do the same.

这篇关于XML到Java映射工具 - 带有映射描述符的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

07-20 19:28