Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/xml/15.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/typo3/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Xml XSD:有一些选择的序列_Xml_Xsd_Xsd Validation - Fatal编程技术网

Xml XSD:有一些选择的序列

Xml XSD:有一些选择的序列,xml,xsd,xsd-validation,Xml,Xsd,Xsd Validation,我有一个不同类型的序列,对于其中一些类型,我想确保最多使用其中一个元素。这里有一些例子:可能只发生一次。存在诸如、、等元素。这些元素中最多允许一个。要么,要么 有效的XML: <Property> <Synchronisation/> </Property> <Property> <Synchronisation/> <Link/> </Property> <Property&g

我有一个不同类型的序列,对于其中一些类型,我想确保最多使用其中一个元素。这里有一些例子:可能只发生一次。存在诸如、、等元素。这些元素中最多允许一个。要么,要么

有效的XML:

<Property>
    <Synchronisation/>
</Property>

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

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

<Property>
    <Synchronisation/>
    <Link/>
    <Label/>
</Property>
无效的XML,如和发生

我试着这样做xsd,但它不起作用:

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

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

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

“不工作”是什么意思?在第5行中有一个错误:`没有声明'ElementType'元素。乍一看,它似乎像其他元素一样使用ref而不是type……当我使用类型时,我也必须使用名称。然后xml必须有一个子元素,包含Textbox、Labelor CheckBox.ref引用命名元素,而不是类型。。。如果父元素是schema元素,则必须指定name,在这种情况下,不能使用ref。根据
<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>