XSD choice inside all

前端 未结 1 997
生来不讨喜
生来不讨喜 2021-01-18 02:01

You can\'t put choice tag inside the all tag. So, is there any workaround to get this functionallity? For example, I have tag like:



        
相关标签:
1条回答
  • 2021-01-18 02:57

    Check this link: http://www.w3.org/wiki/Needs_choice_inside_all

    I summarize for you the solutions proposed:

    One solution is to wrap the element that can change inside another:

      <xsd:all>
       <xsd:element minOccurs="0" maxOccurs="1" ref="sending" />
       <xsd:element minOccurs="0" maxOccurs="1" ref="logging"/>
       <xsd:element minOccurs="0" maxOccurs="1" ref ="usetype"/>
      </xsd:all>
    
     <xsd:element name="usetype">
      <xsd:complexType>
       <xsd:choice>
        <xsd:element ref="useonly"/>
        <xsd:element ref="notuseonly"/>
       </xsd:choice>
      </xsd:complexType>
     </xsd:element>
    

    The other one is to use a substitution group:

      <xsd:all>
       <xsd:element ref="sending"/>
       <xsd:element ref="logging"/>
       <xsd:element ref="usetype"/>
      </xsd:all>
     </xsd:complexType>
     <xsd:element name="usetype" abstract="true"/>
     <xsd:element name="useonly" substitutionGroup="usetype"> ... </xsd:element>
     <xsd:element name="notuseonly" substitutionGroup="usetype"> ... </xsd:element>
    
    0 讨论(0)
提交回复
热议问题