我准备了complexType
,一个具有两个属性的枚举:
<xsd:complexType name="Action">
<xsd:simpleContent>
<xsd:restriction base="xsd:string">
<xsd:enumeration value="A"/>
<xsd:enumeration value="B"/>
<xsd:enumeration value="C"/>
</xsd:restriction>
</xsd:simpleContent>
<xsd:attribute name="attrA" type="xsd:string" />
<xsd:attribute name="attrB" type="xsd:string" />
</xsd:complexType>
问题是,JAXB
阻止我为该代码创建 Java 类,我收到以下错误:
When is used, the base type must be a complexType whose content type is simple, or, only if restriction is specified, a complex type with mixed content and emptiable particle, or, only if extension is specified, a simple type. 'string' satisfies none of these conditions.
在线 validator 显示我的代码是正确的。如何更改此设置以使 xjc
转换我的架构定义?
最佳答案
您的 xsd 格式不正确。尝试下面的complexType
<xs:complexType name="Action">
<xs:simpleContent>
<xs:extension base="ActionValue">
<xs:attribute name="attrA" type="xs:string" />
<xs:attribute name="attrB" type="xs:string" />
</xs:extension>
</xs:simpleContent>
</xs:complexType>
<xs:simpleType name="ActionValue">
<xs:restriction base="xs:string">
<xs:enumeration value="A" />
<xs:enumeration value="B" />
<xs:enumeration value="C" />
</xs:restriction>
</xs:simpleType>
关于java - 如何更正 JAXB 生成器的 XSD?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33896646/