问题描述
我正在使用带有setting.ValidationType的2.0 XmlReaderSettings对象设置
到ValdationType.Schema来根据模式验证文档。
关注是一个模式片段(名称已更改):
< xsd:element name =" Stuff">
< xsd:complexType>
< xsd:sequence>
< xsd:element ref =" RequiredSimpleThing1" />
< xsd:element ref =" RequiredSimpleThing2" / >
< xsd:element name =" OptionalSimpleThing1" type =" OptionalType"
minOccurs =" 0" />
< xsd:element name =" OptionalSimpleThing2" type =" OptionalType"
minOccurs =" 0" />
< xsd:element name =" ComplexThing" minOccurs =" 0">
< xsd:complexType>
< xsd:sequence maxOccurs =" unbounded">
< xsd:element name =" ChildThing" type =" ChildType" />
< / xsd:sequence>
< / xsd:complexType>
< / xsd:element>
< / xsd:sequence>
< / xsd:complexType>
< / xsd:element>
以下是一个文件片段:
< Stuff>
< RequiredSimpleThing1> 86876< / RequiredSimpleThing1>
< RequiredSimpleThing2> MC< / RequiredSimpleThing2>
< ComplexThing>
<! - 几个ChildThing元素 - >
< / ComplexThing>
< / Stuff>
我从验证器收到的错误是元素''东西''有
无效的子元素''ComplexThing''。可能元素列表
预期:''OptionalSimpleThing1,OptionalSimpleThing2''。"
为什么验证器需要这些可选(minOccurs = 0)元素?
I''m using a 2.0 XmlReaderSettings object with setting.ValidationType set
to ValdationType.Schema to validate a document against a schema.
Following is a schema fragment (names altered):
<xsd:element name="Stuff">
<xsd:complexType>
<xsd:sequence>
<xsd:element ref="RequiredSimpleThing1"/>
<xsd:element ref="RequiredSimpleThing2"/>
<xsd:element name="OptionalSimpleThing1" type="OptionalType"
minOccurs="0"/>
<xsd:element name="OptionalSimpleThing2" type="OptionalType"
minOccurs="0"/>
<xsd:element name="ComplexThing" minOccurs="0">
<xsd:complexType>
<xsd:sequence maxOccurs="unbounded">
<xsd:element name="ChildThing" type="ChildType"/>
</xsd:sequence>
</xsd:complexType>
</xsd:element>
</xsd:sequence>
</xsd:complexType>
</xsd:element>
Following is a document fragment:
<Stuff>
<RequiredSimpleThing1>86876</RequiredSimpleThing1>
<RequiredSimpleThing2>MC</RequiredSimpleThing2>
<ComplexThing>
<!-- several ChildThing elements -->
</ComplexThing>
</Stuff>
The error I recieve from the validator is "The element ''Stuff'' has
invalid child element ''ComplexThing''. List of possible elements
expected: ''OptionalSimpleThing1, OptionalSimpleThing2''."
Why is the validator requiring these optional (minOccurs = 0) elements?
推荐答案
对我来说还行。也许你的帖子过于简单了。
发布一些真正的文件(如有必要,删除并更改名称),产生错误。
Looks OK to me. Perhaps you have oversimplified in your post.
Post some real files (cut down and names changed if necessary) that produce
the error.
有充分理由不使用全部。
是 - 在抽象建模中条款是正确的,但在实践中它绝不是好主意。
There are good reasons not to use "all".
Yes - in abstract modelling terms it is correct but in practice it is never
a good idea.
这篇关于无法理解架构验证错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!