如何更正 JAXB 生成器的 XSD?
How do I correct XSD for JAXB generator?
我准备了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.
在线验证器告诉我我的代码是正确的。我如何更改它以使 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>
我准备了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.
在线验证器告诉我我的代码是正确的。我如何更改它以使 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>