问题描述
从XSD生成Java类时,如何指定对于某个特定节点,应该使用特定且已存在的Java类而不是尝试生成一个?
When generating Java classes from a XSD, how can I specify that for some specific node, a specific and already existent Java class should be used instead of trying to generate one?
非常感谢。
推荐答案
您可以使用剧集
文件引用现有的类。 .episode
文件只是 jaxb
绑定文件,并且在元素和java类之间有映射。
You can use episode
file to reference the existing classes. .episode
files are just jaxb
bindings file and has mappings between elements and java classes.
a)如果那些现有的类也是从(另一个)xsd生成的。使用以下选项首先创建.episode文件。
a) if those existing classes are also generated from (another) xsd. use below option to first create .episode file.
xjc -episode a.episode a.xsd
然后使用此 a.episode
包含映射作为下一个输入 xjc
代。
then use this a.episode
that contains the mappings as input to the next xjc
generation.
xjc b.xsd -extension -b a.episode
b)如果你想引用一些随机类,那么你可能必须编写自己的剧集文件,提供元素
和类参考
之间的映射,如下所示。
b) If you want to refer some random classes, then you may have to write your own episode file providing mapping between element
and class reference
like below.
sample.episode
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<jaxb:bindings xmlns:jaxb="http://java.sun.com/xml/ns/jaxb" if-exists="true" version="2.1">
<jaxb:bindings scd="x-schema::">
<jaxb:bindings scd="employee">
<jaxb:class ref="www1.example.Employee"/>
<jaxb:package name="www1.example" />
</jaxb:bindings>
</jaxb:bindings>
并使用 xjc b.xsd -extension -b sample.episode
这篇关于Jaxb:如何为XSD元素指定默认类的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!