使用 XJC 从多个 XSD 生成 Java 类

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/10531781/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-31 01:26:58  来源:igfitidea点击:

Generate Java classes from multiple XSDs with XJC

javajaxbxjc

提问by kavai77

I have two xsd files:

我有两个 xsd 文件:

base.xsd:

基础.xsd

<schema
  targetNamespace="http://www.myorg.com/base"
  elementFormDefault="qualified"
  attributeFormDefault="unqualified"
  xmlns="http://www.w3.org/2001/XMLSchema">
...
<complexType name="NrmClass">
    ...
</complexType>
...
</schema>

main.xsdis a schema where we want to use a type from base.xsd

main.xsd是我们想要使用 base.xsd 中的类型的模式

<schema
  targetNamespace="http://www.myorg.com/main"
  elementFormDefault="qualified"
  xmlns="http://www.w3.org/2001/XMLSchema"
  xmlns:xn="http://www.myorg.com/base">

<import namespace="http://www.myorg.com/base"/>
...
<element>
  <complexType>
    <complexContent>
      <extension base="xn:NrmClass">
...

      </extension>
    </complexContent>
  </complexType>
</element>
...
</schema>

When I try to compile both, I receive the following error:

当我尝试编译两者时,我收到以下错误:

> xjc base.xsd main.xsd
parsing a schema...
[ERROR] src-resolve: Cannot resolve the name 'xn:NrmClass' to a(n) 'type definition' component.
  line 48 of file:/main.xsd

What is wrong here?

这里有什么问题?

采纳答案by Patrice M.

You want to try specifying the file for the XSD you're importing, as in:

您想尝试为要导入的 XSD 指定文件,如下所示:

<xsd:import namespace="http://www.myorg.com/base" schemaLocation="base.xsd"/>

This works well if you keep them side by side anyway. That way you can compile them in one operation.

无论如何,如果您将它们并排放置,则效果很好。这样您就可以在一次操作中编译它们。

If you want to run xjc separately (like they are built as separate modules), then you can use an episode file.

如果您想单独运行 xjc(就像它们被构建为单独的模块一样),那么您可以使用剧集文件。