【发布时间】: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