代码之家  ›  专栏  ›  技术社区  ›  scher

XSD:具有一些选择的序列

  •  0
  • scher  · 技术社区  · 7 年前

    <Synchronisation> <Link> 可能发生一次。有如下元素 <TextBox> , <Label> <CheckBox> <文本框(>); , <标签> < .

    有效XML:

    <Property>
        <Synchronisation/>
    </Property>
    
    <Property>
        <Synchronisation/>
        <Link/>
    </Property>
    
    <Property>
        <Synchronisation/>
        <Link/>
        <TextBox/>
    </Property>
    
    <Property>
        <Synchronisation/>
        <Link/>
        <Label/>
    </Property>
    

    无效的XML,如 < <标签> 发生。

    <Property>
        <Synchronisation/>
        <Link/>
        <Label/>
        <TextBox/>
    </Property>
    

    <xsd:complexType name="PropertyType">
        <xsd:sequence minOccurs="0">
            <xsd:element minOccurs="0" maxOccurs="1" name="Synchronisation" type="SynchronisationType"/>
            <xsd:element minOccurs="0" maxOccurs="1" name="Links" type="LinksType"/>
            <xsd:element minOccurs="0" maxOccurs="1" ref="ElementType"/>
        </xsd:sequence>
    </xsd:complexType>
    
    <xsd:complexType name="ElementType">
        <xsd:choice>
            <xsd:element name="TextBox" type="TextBoxType"/>
            <xsd:element name="Label" type="TextBoxType"/>
            <xsd:element name="CheckBox" type="TextBoxType"/>
        </xsd:choice>
    </xsd:complexType>
    
    1 回复  |  直到 7 年前
        1
  •  1
  •   scher    7 年前

    最后,我找到了问题的解决方案:

    <xsd:complexType name="PropertyType">
        <xsd:sequence minOccurs="0">
            <xsd:element minOccurs="0" maxOccurs="1" name="Synchronisation" type="SynchronisationType"/>
            <xsd:element minOccurs="0" maxOccurs="1" name="Links" type="LinksType"/>
            <xsd:choice minOccurs="0" maxOccurs="1"/>
                <xsd:element minOccurs="0" maxOccurs="1" name="TextBox" type="TextBoxType" /> 
                <xsd:element minOccurs="0" maxOccurs="1" name="Label" type="LabelType" /> 
                <xsd:element minOccurs="0" maxOccurs="1" name="CheckBox" type="CheckBoxType" /> 
            </xsd:choice>
        </xsd:sequence>
    </xsd:complexType>