Reputation: 20182
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
Upvotes: 0
Views: 272
Reputation: 21638
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.
Upvotes: 1
Reputation: 5427
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.
Upvotes: 0
Reputation: 38122
You could split abstractRequest in 2 types, one (A) extending the other (B), where A defines the part only needed for A. Your requestExtension then can extend B and thus won't have the unwanted parts.
Upvotes: 0