简体   繁体   中英

how to extend complexType but have no children elements in subtype?

I currently have the following part of an xsd...

<xs:element name="requestExtension">
    <xs:complexType>
        <xs:complexContent>
            <xs:extension base="abstractRequest"> 
                <xs:sequence>
                        <xs:element name="unusedReqPart" type="xs:string" minOccurs="0"/>   
                    </xs:sequence>
                </xs:extension>
            </xs:complexContent>
    </xs:complexType>
</xs:element>   

I need the requestExtension to extend abstractRequest but how do I get rid of the unusedReqPart so my jaxb generation still works?

EDIT for clarity: I "want" the elements of the super class to be included. I do not want to remove them. I only want the subtype's element above called "unusedReqPart" to be removed. I only put it there temporarily so that my jaxb stuff compiles correctly. I have it adhering to an existing protocol already by using minOccurs="0" there as that element is never used(so I would prefer to completely remove it if I can).

thanks, Dean

It almost feels like a trick question... Unless the language is what it is, then it is as simple as:

<xs:element name="requestExtension"> 
    <xs:complexType> 
        <xs:complexContent> 
            <xs:extension base="abstractRequest"/>
        </xs:complexContent> 
    </xs:complexType> 
</xs:element>

There is no reason why you wouldn't extend it using the "empty" particle. In turn, it allows you to have a concrete (hence usable) type without any new content on top of the base type.

I am sure you wouldn't want to go with the restriction (as described in one the answers); the effect there it is that it wipes out the entire content model (effectively makes it empty).

I would be surprised to hear that JAXB wouldn't work with I am proposing above; if you find it doesn't, please update your post with the particular version number of JAXB you're using, and a snippet of the generated class that doesn't pass your validation.

您可以将abstractRequest分为两种类型,一种(A)扩展另一种(B),其中A定义仅用于A的部分。您的requestExtension然后可以扩展B,因此不会有不需要的部分。

When you would want to restrict the elements from parent, you should use as below:

<xs:restriction base="abstractRequest">
   <xs:sequence>

  </xs:sequence>
</xs:restriction>

That would stop the elements from being generated in children from parent.

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