Reputation: 642
Question: It is possible to have the same behavior in xsd objects definition like in Java generic?
So what basically I need is the Soap method to return the xml object type to be the concrete type of the returned object (one of the children) and not the parent object, the base type. Basically the wsdl to say that the returned object is the parent object, or one of the children.
More concrete:
Java:
public <T extends BaseObject> T getData(){
....
return oneOfTheChildObjectsOfBaseObject;
}
xsd:
<xs:complexType name="baseObject">
<xs:complexContent>
<xs:sequence>
<xs:element name="element1" type="xs:string"/>
</xs:sequence>
</xs:complexContent>
</xs:complexType>
<xs:complexType name="Child1">
<xs:complexContent>
<xs:extension base="tns:baseObject">
.... specific child props
</xs:extension>
</xs:complexContent>
</xs:complexType>
<xs:complexType name="Child2">
<xs:complexContent>
<xs:extension base="tns:baseObject">
.... specific child props
</xs:extension>
</xs:complexContent>
</xs:complexType>
Upvotes: 0
Views: 293
Reputation: 2422
A SOAP message is just an XML document with an envelope that conforms to the SOAP schema and a <body>
tag that conforms to the schema for one of the operation types.
The standard way to do what you require in XML is to supply the concrete type of the element using an xsi:type attribute. The type that you specify must be derived from the base type, otherwise the XML processor should report an error. Depending on how the XSD is constructed, there may be other rules about which types are allowed.
For completeness you may also want to read about substitution groups - they offer equivalent mechanisms for elements rather than types.
Upvotes: 1