【问题标题】:Element type in xsd is referring its own Complex typexsd 中的元素类型是指它自己的复杂类型
【发布时间】:2019-07-22 21:04:03
【问题描述】:

我有这样的xsd -

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

在这里您可以看到我的childChoices 类型是ChoiceListItem,它是在其下定义的。这是我的 Java 类 -

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

当我在 SOAPUI 中运行它时,它没有显示 childChoices 值,而是显示了其他三个项目。这是我的输出响应 -

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

我猜 xsd 定义不正确..有人可以帮我定义正确的 xsd,其中序列元素类型引用相同的复杂类型吗?

【问题讨论】:

    标签: soap xsd schema xsd-validation complextype


    【解决方案1】:

    我已经通过更改我的 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>
    

    【讨论】:

      猜你喜欢
      • 2015-07-11
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多