2017-07-26 16 views
0

Ich habe eine Sequenz von verschiedenen Typen, für einige von ihnen möchte ich sicherstellen, dass höchstens eines dieser Elemente verwendet wird. Hier einige Beispiele: <Synchronisation> und <Link> können einmal auftreten. Es gibt Elemente wie <TextBox>, <Label>, usw. Von diesen Elementen ist höchstens eins erlaubt. Entweder <TextBox>, <Label> oder .XSD: Sequenz mit einer Auswahl

Valid XMLs:

<Property> 
    <Synchronisation/> 
</Property> 

<Property> 
    <Synchronisation/> 
    <Link/> 
</Property> 

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

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

Ungültige XML, als <TextBox> und <Label> occures.

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

Ich versuchte, die XSD wie dies zu tun, aber es funktioniert nicht:

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

Was meinen Sie mit " funktioniert nicht"? –

+0

In Zeile 5 gibt es einen Fehler: 'Das Element 'ElementType' ist nicht deklariert." – scher

+0

Nun, auf den ersten Blick scheint es, dass 'ref' anstelle von' type' verwendet wird, wie die anderen ... –

Antwort

1

Schließlich fand ich eine Lösung für das Problem:

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