XML Schema: all, sequence &团体 [英] XML Schema: all, sequence & groups

查看:16
本文介绍了XML Schema: all, sequence &团体的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是第一次编写 XML 模式,我找到了一些有用的工具来帮助我编写它.

I'm writing an XML schema for the first time and I found some usefull tools to help me writing it.

现在我的处境很奇怪.我编写的模式对某些工具有效,而对其他一些工具无效.该模式是全部"、序列"和序列"的混合.和组".这是我的 XML 架构:

Now I'm in a strange situation. The schema I wrote is valid for some tools and not for some others. This schema is a mix of "all", "sequence" and "group". Here is my XML schema:

<?xml version="1.0" encoding="utf-8"?>
<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema">
     <xsd:group name="test">

        <xsd:all>
                <xsd:element name="e2" minOccurs="0" maxOccurs="1"/>
                <xsd:element name="e3" minOccurs="0" maxOccurs="1"/>
                <xsd:element name="e4" minOccurs="0" maxOccurs="1"/>
        </xsd:all>
    </xsd:group>

    <xsd:element name="e0">
        <xsd:complexType>
            <xsd:sequence>
                <xsd:element name="e1" maxOccurs="unbounded"/>
                <xsd:group ref="test"/>
            </xsd:sequence>
        </xsd:complexType>
    </xsd:element>
</xsd:schema>

这个架构对吗?它与 这个验证器这个也是,但是 Notepad++ 的 XML 工具插件说无法解析模式文件".

Is this schema right? It goes right with this validator and this one too but the XML Tools plugin for Notepad++ says "Unable to parse schema file".

P.S:我写这个模式是因为我想要一个元素e0".这样就有可能混合使用 e1、e2、e3 和 e4.e2、e3 和 e4 应该出现 0 或 1 次,而 e1 可能出现无限次.例如这个 XML 文件应该通过:

P.S: I wrote this schema because I wanted to have an element "e0" with this the possibility to have a mix of e1, e2, e3 and e4. e2, e3 and e4 should appear 0 or 1 time and e1 could occurs an illimited times. For example this XML files should pass:

<e0>
   <e1/>
   <e1/>
   <e1/>
   <e1/>
   <e1/>
   <e2/>
</e0>

<e0>
   <e2/>
   <e3/>
   <e4/>
</e0>

<e0>
   <e1/>
   <e2/>
   <e3/>
   <e4/>
</e0>

你知道另一种方法吗?

谢谢

推荐答案

根据声明 这里很明显(初级)那个

XML Schema 规定 all 组必须作为唯一的子项出现在内容模型的顶部.

或者,尝试在这里阅读 XML Schema Structures 的第 3.8.6 节.在您的列表中,我将添加 .NET 的 XSD 处理器,在您的情况下会抱怨:

Alternatively, try to read section 3.8.6 of the XML Schema Structures here. To your list I would add .NET's XSD processor, which in your case will complain as:

'all' 的组引用不是根粒子,或者它被用作扩展.

对于 XSD 1.0,除非您为 e1 元素(以下为 e1s)构建一个包装器,否则没有任何解决方案可以用简洁的语法很好地满足您的需求.

With XSD 1.0 there is no solution that would give you what you want nicely and with a concised syntax unless you build a wrapper for e1 elements (below as e1s).

<?xml version="1.0" encoding="utf-8"?>
<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema">
    <xsd:group name="test">
        <xsd:all>
            <xsd:element name="e1s" minOccurs="0">
                <xsd:complexType>
                    <xsd:sequence>
                        <xsd:element name="e1" maxOccurs="unbounded"/>
                    </xsd:sequence>
                </xsd:complexType>
            </xsd:element>
            <xsd:element name="e2" minOccurs="0"/>
            <xsd:element name="e3" minOccurs="0"/>
            <xsd:element name="e4" minOccurs="0"/>
        </xsd:all>
    </xsd:group>
    <xsd:element name="e0">
        <xsd:complexType>
            <xsd:group ref="test"/>
        </xsd:complexType>
    </xsd:element>
</xsd:schema> 

说到e1元素,必须用e1s包裹起来

When it comes to e1 elements, they must be wrapped in e1s

<e0>
    <e1s>
        <e1/>
        <e1/>
        <e1/>
        <e1/>
        <e1/>
    </e1s>
    <e2/>
</e0>  

<e0>
    <e1s>
        <e1/>
    </e1s>
    <e2/>
    <e3/>
    <e4/>
</e0>     

然后一切都会验证...

Then it'll all validate...

这篇关于XML Schema: all, sequence &amp;团体的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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