我正在尝试为 XML 生成一个非常简单的 XML 架构,类似于以下内容:
<messages>
<item>
<important_tag></important_tag>
</item>
<item>
<important_tag></important_tag>
<tag2></tag2>
</item>
<item>
<tag2></tag2>
<tag3></tag3>
</item>
</messages>
这个想法是<important_tag>
将有一个具体的定义,并且它可能会也可能不会出现在<item>
。它也可能出现多次。
此外,之前或之后可能还有其他标签<important_tag>
我无法提前命名。
我想给一个具体的定义<important_tag>
。例如,定义它必须包含的属性。
我的意思是ifimportant_tag 存在它必须符合我的定义。任何其他标签不必符合任何定义。
我尝试使用以下方案:
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">
<xs:element name="messages">
<xs:complexType>
<xs:sequence>
<xs:element ref="item" maxOccurs="unbounded"/>
</xs:sequence>
</xs:complexType>
</xs:element>
<xs:element name="item">
<xs:complexType>
<xs:sequence>
<xs:element ref="important_tag" minOccurs="0"/>
<xs:any minOccurs="0"/>
</xs:sequence>
</xs:complexType>
</xs:element>
<xs:element name="important_tag">
<xs:complexType>
<xs:simpleContent>
... specific definitions for important_tag ...
</xs:simpleContent>
</xs:complexType>
</xs:element>
</xs:schema>
这会导致错误,指出架构不明确。
确切的错误消息是:
cos-nonambig: '<xs:element ref="important_tag">' makes the content model non-deterministic against '<xs:any>'. Possible causes: name equality, overlapping occurrence or substitution groups.
我正在使用 Altova XMLSpy。
我该如何解决这个问题?
谢谢,
达纳
MSDN 上有一篇很棒的文章讨论了设计可扩展模式,您可以找到here http://msdn.microsoft.com/en-us/library/ms950793.aspx,我建议您仔细阅读所有内容,但具体到您的观点,它解释了为什么您在“使用 XML 架构设计可版本化的 XML 格式”下的第 2 点中收到此错误(您可以搜索“非确定性”和直接到那里。
基本上,一旦您拥有 xs:any 元素,验证器就无法假设有关其他同级元素的任何信息,因此 - 您很可能有一个 important_tag 的定义,它不需要这些强制属性,因此无法验证这些元素
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)