简体   繁体   中英

How do I correct XSD for JAXB generator?

I prepared complexType , an enum with two attributes:

<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>

The problem is, JAXB prevents me from creating Java classes for that code, I get the following error:

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.

Online validator showed me my code is corrent one. How do I change this to make xjc convert my schema definition?

Your xsd is not well formed. Try below 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>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM