【问题标题】:Need help with (recursive) xsd group需要(递归)xsd 组的帮助
【发布时间】:2010-10-21 10:48:51
【问题描述】:

我有这个 xsd:

<?xml version="1.0" encoding="utf-8" ?>
<xs:schema xmlns="http://myschema.com/schema"
           targetNamespace="http://myschema.com/schema"
           xmlns:xs="http://www.w3.org/2001/XMLSchema">
    <xs:complexType name="aType" mixed="true">
        <xs:group ref="aElements" minOccurs="0" maxOccurs="unbounded"/>
    </xs:complexType>

    <xs:group name="aElements">
        <xs:choice>
            <xs:element name="a" type="aType"/>
        </xs:choice>
    </xs:group>

    <xs:element name="b">
        <xs:complexType>
            <xs:choice minOccurs="0" maxOccurs="unbounded">
                <xs:group ref="aElements"/>
            </xs:choice>
        </xs:complexType>
    </xs:element>
</xs:schema>

我尝试验证这个 xml 文档:

<?xml version="1.0" encoding="utf-8" ?>
<b xmlns="http://myschema.com/schema">
    <a/>
</b>

然而,Visual Studio 2008 的 xml 验证器抱怨 元素:

命名空间“http://myschema.com/schema”中的元素“b”在命名空间“http://myschema.com/schema”中具有无效的子元素“a”。预期的可能元素列表:'a'。

有什么问题?

编辑:糟糕,在简化示例时,我忘记将元素设为可选元素,导致无限递归。不过,这个模组的问题仍然存在。


回答:答案是 xs:schema 标记应该包含 elementFormDefault="qualified" 属性。

【问题讨论】:

    标签: xsd


    【解决方案1】:

    使用编辑器进行 XSD 开发可以让您的生活更轻松。我们已经使用 Liquid XML Studio 很多年了,它让生活更轻松。

    【讨论】:

      【解决方案2】:

      您将aElements 定义为aType,将aType 定义为aElements。我不是 xsd 专家,但这应该如何工作?

      【讨论】: