我正在开发一个使用XJC从XSD生成Java POJO的应用程序.有几十种模式,这个数字会增长.应用程序还需要能够处理相同模式的不同版本,这意味着我将有多个模式定义常见类型.我正在尝试自定义绑定,以便某些核心类型实现一个通用接口.JAXB2 Basics的继承插件似乎做了我需要的东西,但我似乎无法确定正确的语法.
这是我的架构的相关部分:
<?xml version="1.0" encoding="UTF-8"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"
xmlns:my="http://example.com/core"
targetNamespace="http://example.com/core"
xmlns:xml="http://www.w3.org/XML/1998/namespace">
...
<xs:complexType name="addressType">
<xs:sequence>
<xs:element name="Address" type="xs:string"/>
<xs:element name="City" type="xs:string"/>
<xs:element name="Province" type="xs:string"/>
<xs:element name="Country" type="xs:string"/>
<xs:element name="County" type="xs:string" minOccurs="0"/>
<xs:element name="PostalCode" type="xs:string"/>
</xs:sequence>
</xs:complexType>
...
</xs:schema>
Run Code Online (Sandbox Code Playgroud)
...这就是我的自定义绑定文件的样子:
<?xml version="1.0"?>
<jaxb:bindings
xmlns:xs="http://www.w3.org/2001/XMLSchema"
xmlns:xjc="http://java.sun.com/xml/ns/jaxb/xjc"
xmlns:jaxb="http://java.sun.com/xml/ns/jaxb"
xmlns:inheritance="http://jaxb2-commons.dev.java.net/basic/inheritance"
xmlns:my="http://example.com/core"
jaxb:extensionBindingPrefixes="inheritance"
version="2.1">
<jaxb:bindings scd="x-schema::my" xmlns:my="http://example.com/core">
<jaxb:globalBindings localScoping="toplevel">
<jaxb:serializable/>
<xjc:simple/>
</jaxb:globalBindings>
<jaxb:bindings scd="/type::my:addressType">
<inheritance:implements>com.mysite.validator.ValidatableAddress</inheritance:implements>
<!--<xjc:superInterface name="com.mysite.validator.ValidatableAddress"/>-->
</jaxb:bindings>
</jaxb:bindings>
</jaxb:bindings>
Run Code Online (Sandbox Code Playgroud)
我正在使用scd方法,因为在所有显示如何使用inheritence插件的"传统"绑定示例中,指定了schemaLocation.我想避免必须指定schemaLocation,因为我们的模式数量很大(且不断增长).我不想每次添加新架构时都必须更改绑定文件.所以,scd似乎会满足这个要求.
但是当我使用上面的绑定运行构建时,我得到了这个:
Run Code Online (Sandbox Code Playgroud)[xjc] [ERROR] cvc-elt.1: Cannot …