用于重复元素序列的 Xml 模式 [英] Xml Schema for repeating sequence of elements

查看:28
本文介绍了用于重复元素序列的 Xml 模式的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的xml如下

<Search>
    <Term />
    <And />
    <Term />
    <And />
    <Term />
</Search>

如图所示,序列中可以有 n 个项和 n-1 个 Ands (n > 0).我尝试了以下 xml 架构,但上面的 xml 不会根据架构进行验证.错误:cvc-complex-type.2.4.b:元素搜索"的内容不完整.应为{And}"之一.

There can be n number of Terms and n-1 Ands (n > 0) in the sequence as shown. I tried the following xml schema but above xml would not get validated against the schema. Error: cvc-complex-type.2.4.b: The content of element 'Search' is not complete. One of '{And}' is expected.

<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" elementFormDefault="qualified">
    <xs:element name="Search">
        <xs:complexType>
            <xs:sequence>               
                <xs:sequence minOccurs="0" maxOccurs="unbounded">
                    <xs:element name="Term" type="xs:string" />
                    <xs:element name="And" type="xs:string" />
                </xs:sequence>              
                <xs:element name="Term" minOccurs="1" maxOccurs="1" type="xs:string" />             
            </xs:sequence>
        </xs:complexType>
    </xs:element>
</xs:schema>

感谢有关 xml 架构的任何帮助.

Appreciate any help with the xml schema.

推荐答案

像这样重新排序似乎可以做到.我错过了什么吗?

Reordering them like this seems to do it. Am I missing anything?

<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" elementFormDefault="qualified">
    <xs:element name="Search">
        <xs:complexType>
            <xs:sequence>
              <xs:element name="Term" minOccurs="1" maxOccurs="1" type="xs:string" />
                <xs:sequence minOccurs="0" maxOccurs="unbounded">
                  <xs:element name="And" type="xs:string" />
                  <xs:element name="Term" type="xs:string" />
                </xs:sequence>
            </xs:sequence>
        </xs:complexType>
    </xs:element>
</xs:schema>

这篇关于用于重复元素序列的 Xml 模式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆