Search code examples
soapxsdschemaxsd-validationcomplextype

Element type in xsd is referring its own Complex type


I have xsd like this -

   <xs:complexType name="ChoiceListItem">
    <xs:sequence>
     <xs:element name="childChoices" maxOccurs="unbounded" minOccurs="0" nillable="true" type="tns:ChoiceListItem"/>
     <xs:element name="name" nillable="true" type="xsd:string"/>
     <xs:element name="stringValue" nillable="true" type="xsd:string"/>
     <xs:element name="integerValue" nillable="true" type="xsd:int"/>
    </xs:sequence>
   </xs:complexType> 

Here you can see that my childChoices type is ChoiceListItem under which it is defined. Here is my Java class -

@XmlAccessorType(XmlAccessType.FIELD)  
@XmlType(name = "ChoiceListItem", propOrder = {
    "childChoices",
    "name",
    "stringValue",
    "integerValue"
})  
public class ChoiceListItem {

    @XmlElement(nillable = true)
    protected List<ChoiceListItem> childChoices;
    @XmlElement(required = true, nillable = true)
    protected String name;
    @XmlElement(required = true, nillable = true)
    protected String stringValue;
    @XmlElement(required = true, type = Integer.class, nillable = true)
    protected Integer integerValue;

When I run it in SOAPUI it did not display the childChoices value but displays the other three items. Here is my output response -

  <ns3:getChoiceListItemsResponse xmlns:ns3="http://getservice.service">
     <getChoiceListItemsReturn>
        <items>
           <ChoiceListItem>
              <name>AD SERVICE</name>
              <stringValue>AD SERVICE</stringValue>
              <integerValue xsi:nil="true" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"/>
           </ChoiceListItem>   

I guess xsd is not defined properly..Can somebody please help me in defining correct xsd in which sequence element type refer to same Complex type?


Solution

  • I have solved it by making changes into my xsd

    <xs:complexType name="ChoiceListItem">
        <xs:sequence>
         <xs:element name="childChoices" nillable="true" type="tns:ChoiceListItemArray"/>
         <xs:element name="name" nillable="true" type="xsd:string"/>
         <xs:element name="stringValue" nillable="true" type="xsd:string"/>
         <xs:element name="integerValue" nillable="true" type="xsd:int"/>
        </xs:sequence>
       </xs:complexType>
       <xs:complexType name="ChoiceListItemArray">
        <xs:sequence>
         <xs:element maxOccurs="unbounded" minOccurs="0" name="ChoiceListItem" nillable="true" type="tns:ChoiceListItem"/>
        </xs:sequence>
       </xs:complexType>