通常在 2 XSD 个文件中具有同名的复杂类型?

Typical to have complexType of same name in 2 XSD Files?

我是 JAXB 的新手,正在处理 XSDs。我正在使用 Maven JAXB2 插件从他们那里编组 类。我是从我需要使用的 Web 服务提供商那里得到的,但我不确定他们的文档是否有误,或者我是否没有正确处理重复。

所以我有两个 XSD 文件 a.xsd 和 b.xsd,它们都位于同一目录中。

在 a.xsd 我有声明:

<xs:complexType name="AttributeType">
    <xs:sequence>
        <xs:element ref="AttributeValue" maxOccurs="unbounded" />
    </xs:sequence>
    <xs:attribute name="AttributeName" type="xs:string" use="required" />
    <xs:attribute name="AttributeNamespace" type="xs:string"
        use="required" />
</xs:complexType>

在 b.xsd 我有 :

<xs:complexType name="AttributeType">
    <xs:sequence>
        <xs:element ref="AttributeValue" maxOccurs="unbounded" />
    </xs:sequence>
    <xs:attribute name="AttributeName" type="xs:string" use="required" />
    <xs:attribute name="AttributeNamespace" type="xs:string"
        use="required" />
</xs:complexType>

我在 Maven 中遇到的错误是

A class/interface with the same name   "com.mycompany.voice.gcs.correspondenceservice.v1.AttributeType" is already in use. Use a class customization to resolve this conflict.

它们看起来和我一模一样,复制它们没有任何意义。但正如我所说,我是新手,所以我想确保我没有遗漏任何东西。

谢谢。 :)

只要这两个模式有不同的命名空间就可以了。查找根架构元素的 targetNamespace 属性。

如果目标命名空间缺失或目标命名空间相同,这可能会出现问题。

这看起来像 "copy-paste" 模式设计,而不是首选的模块化设计,但如果不看模式很难判断。

"Copy-paste"设计并非非典型,但也不是一个好的做法。

服务提供商给我错误的文件,其中包含重复的复杂类型。结果,重复项失败了。