Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/arduino/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 使用xs:extension忽略元素的顺序_Xml_Xsd - Fatal编程技术网

Xml 使用xs:extension忽略元素的顺序

Xml 使用xs:extension忽略元素的顺序,xml,xsd,Xml,Xsd,如何设计xsd以忽略元素序列 <root> <a/> <b/> </root> 但是,此xsd无效,以下错误报告在中: cos all limited.1.2:所有模型组必须出现在{min occurs}={max occurs}=1的粒子中,并且该粒子必须是构成复杂类型定义的{content type}的一对粒子的一部分 文件说明: 1.2{max occurs}=1的粒子的{term}属性,它是构成复杂类型定义{content type}的

如何设计xsd以忽略元素序列

<root> <a/> <b/> </root>

但是,此xsd无效,以下错误报告在
中:

cos all limited.1.2:所有模型组必须出现在{min occurs}={max occurs}=1的粒子中,并且该粒子必须是构成复杂类型定义的{content type}的一对粒子的一部分

文件说明:

1.2{max occurs}=1的粒子的{term}属性,它是构成复杂类型定义{content type}的一对粒子的一部分

我真的不明白这一点(无论是xsd还是英语母语:))



我是否做了错事,我是否做了错事,还是没有办法做到这一点

主要编辑最初我忽略了需要使用
xsd:extension
的要求。请注意,
xsd:extension
的工作原理就好像存在
xsd:sequence
一样,基本类型的内容后跟扩展类型的内容。正如XML Schema Primer所说:

当复杂类型由派生时 扩展,它的有效内容模型 是基类型的内容模型 加上中指定的内容模型 类型派生。此外 两个内容模型被视为两个 连续组的孩子

因此,实现这一点的唯一方法似乎是使用空的基类型并将整个替换存储在扩展类型中,反之亦然(基中的所有内容和空扩展)。像这样:

<xsd:complexType name="ExtendedType">
   <xsd:complexContent>
      <xsd:extension base="BaseType">
         <xsd:choice>
            <xsd:sequence>
               <xsd:element name="a" type="xsd:string"/>
               <xsd:element name="b" type="xsd:string"/>
            </xsd:sequence>
            <xsd:sequence>
               <xsd:element name="b" type="xsd:string"/>
               <xsd:element name="a" type="xsd:string"/>
            </xsd:sequence>
         </xsd:choice>
      </xsd:extension>
   </xsd:complexContent>
</xsd:complexType>

<xsd:complexType name="BaseType"/>

<xsd:element name="root" type="ExtendedType"/>



以下是对限制的解释:

使用“all”模型对复杂类型进行的唯一扩展是添加一些属性。不能使用新元素进行扩展

就我而言,我做过类似的事情:

<?xml version="1.0" encoding="UTF-8"?>
<xs:schema targetNamespace="http://www.example.com/test"
           xmlns:xs="http://www.w3.org/2001/XMLSchema"
           xmlns:t="http://www.example.com/test" >

    <xs:complexType name="BaseType">
        <xs:all>
            <xs:element name="a" type="xs:string" />
        </xs:all>
    </xs:complexType>

    <xs:complexType name="ExtendedType">
        <xs:all>
            <xs:element name="a" type="xs:string" /> <!-- copy/paste from BaseType -->
            <xs:element name="b" type="xs:string" />
        </xs:all>
    </xs:complexType>

    <xs:element name="root" type="t:ExtendedType"></xs:element>
</xs:schema>


感谢您的更新。不幸的是,我需要在基本类型中定义一些元素,在扩展类型中定义一些元素,因此除非有其他方法,否则扩展类型的元素将始终必须放在基本类型的元素之后…@Peter在这种情况下,因为“两个内容模型被视为一个连续组的两个子元素”,所以没有办法(据我所知)忽略顺序。我已经假设…也许其他人有任何想法,否则我将坚持我的解决方案并强制“正确”元素的顺序。谢谢你们的时间,真的很感谢!是的,但如果我有比元素更多的元素,我怎么写这个?@Bolo所以你们必须列出元素在自己的顺序中的所有可能的顺序?如果你们有5个元素,你们必须定义所有120个序列???@Ruslan:你们试过了吗?它将强制执行顺序在
b
之前的
a
的e,所以它实际上对我没有帮助。。。
<xsd:complexType name="ExtendedType">
   <xsd:complexContent>
      <xsd:extension base="BaseType">
         <xsd:choice>
            <xsd:sequence>
               <xsd:element name="a" type="xsd:string"/>
               <xsd:element name="b" type="xsd:string"/>
            </xsd:sequence>
            <xsd:sequence>
               <xsd:element name="b" type="xsd:string"/>
               <xsd:element name="a" type="xsd:string"/>
            </xsd:sequence>
         </xsd:choice>
      </xsd:extension>
   </xsd:complexContent>
</xsd:complexType>

<xsd:complexType name="BaseType"/>

<xsd:element name="root" type="ExtendedType"/>
<xs:complexType name="BaseType"> 
    <xs:sequence> 
        <xs:element name="a" type="xs:string" /> 
    </xs:sequence> 
</xs:complexType> 

<xs:complexType name="ExtendedType"> 
    <xs:complexContent> 
        <xs:extension base="t:BaseType"> 
            <xs:sequence> 
                <xs:element name="b" type="xs:string" /> 
            </xs:sequence> 
        </xs:extension> 
    </xs:complexContent> 
</xs:complexType> 

<xs:element name="root" type="t:ExtendedType"></xs:element> 
<?xml version="1.0" encoding="UTF-8"?>
<xs:schema targetNamespace="http://www.example.com/test"
           xmlns:xs="http://www.w3.org/2001/XMLSchema"
           xmlns:t="http://www.example.com/test" >

    <xs:complexType name="BaseType">
        <xs:all>
            <xs:element name="a" type="xs:string" />
        </xs:all>
    </xs:complexType>

    <xs:complexType name="ExtendedType">
        <xs:all>
            <xs:element name="a" type="xs:string" /> <!-- copy/paste from BaseType -->
            <xs:element name="b" type="xs:string" />
        </xs:all>
    </xs:complexType>

    <xs:element name="root" type="t:ExtendedType"></xs:element>
</xs:schema>