您可能遇到的问题之一称为唯一粒子归因。这一切都取决于你想要的元素可能包含哪些命名空间。
最糟糕的情况是任何命名空间。因此,接受您的要求(与InfantPro'Aravind'不同,后者通过将content-section设置为必填项,并且将您的任何元素的maxOccurs限制为任意数字来解决问题),这是我们从哪里开始(不良错误,违反UPA)。首先,解决任何的maxOccurs的允许1 or more elements to be placed in the location
:
<?xml version="1.0" encoding="utf-8" ?>
<!-- XML Schema generated by QTAssistant/XSD Module (http://www.paschidev.com) -->
<xsd:schema attributeFormDefault="unqualified" elementFormDefault="qualified" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<xsd:element name="content">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="metadata" minOccurs="0" maxOccurs="unbounded"/>
<xsd:any maxOccurs="unbounded"/>
<xsd:element name="content-section" minOccurs="0" maxOccurs="unbounded"/>
<xsd:element name="content-footer" minOccurs="0" maxOccurs="unbounded"/>
</xsd:sequence>
</xsd:complexType>
</xsd:element>
</xsd:schema>
错误是:
Error occurred while loading [how-can-i-describe-an-element-with-some-any-child-element-and-some-known.xsd], line 8 position 6.
Wildcard '##any' allows element 'metadata', and causes the content model to become ambiguous. A content model must be formed such that during validation of an element information item sequence, the particle contained directly, indirectly or implicitly therein with which to attempt to validate each item in the sequence in turn can be uniquely determined without examining the content or attributes of that item, and without any information about the items in the remainder of the sequence.
现在你需要解决这个问题。这是你的选择:
1)限制任何别的东西(例如##等)的命名空间:
<xsd:any maxOccurs="unbounded" namespace="##other"/>
如果你不能限制你的命名空间,这是你的选择:
2)包住any
内容到另一个元件(称为扩展):
<?xml version="1.0" encoding="utf-8" ?>
<!-- XML Schema generated by QTAssistant/XSD Module (http://www.paschidev.com) -->
<xsd:schema attributeFormDefault="unqualified" elementFormDefault="qualified" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<xsd:element name="content">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="metadata" minOccurs="0" maxOccurs="unbounded"/>
<xsd:element name="extension"/>
<xsd:element name="content-section" minOccurs="0" maxOccurs="unbounded"/>
<xsd:element name="content-footer" minOccurs="0" maxOccurs="unbounded"/>
</xsd:sequence>
</xsd:complexType>
</xsd:element>
</xsd:schema>
所有其它涉及移动底部的any
内容。
3)将您的any
右移到底部,并在其前面加上一个必需元素。
如果你想要这种类型的全球性,并允许它不是最终的,那么你进入其他模式。
很好解释..我想我应该给出类似的解释,而不是显示过度使用'any':P – 2013-03-14 13:03:47
太棒了!我最终添加了另一个元素。选项2.感谢您的答案! – Nick 2013-03-14 13:05:53