<xsd:all> 之间的区别和 <xsd:sequence>在模式定义中? [英] Difference between <xsd:all> and <xsd:sequence> in schema definition?
问题描述
我在复杂类型中使用 xsd:all
.当我在验证时错过任何强制性元素时,它将显示所有元素.它不会显示准确的遗漏元素.
I am using xsd:all
in a complex type. When I miss any mandatory elements while validating it will show all the elements. It will not display the exact missed element.
但如果我使用 xsd:sequence
我可以得到准确的遗漏元素.
But if I am use xsd:sequence
I can get the exact missed element.
这两者有什么区别吗?
xsd:sequence
:XML 元素的顺序必须一致.
xsd:sequence
: XML element must be in same order.
但是xsd:all
:XML元素可以是任意顺序.
But xsd:all
: XML element may be any order.
推荐答案
<xsd:all>
指定子元素可以按任意顺序出现.
<xsd:all>
specifies that the child elements can appear in any order.
<xsd:sequence>
指定子元素只能按提到的顺序出现.
<xsd:sequence>
specifies child elements can only appear in the order mentioned.
序列示例:
<xs:element name="compElement">
<xs:complexType>
<xs:sequence>
<xs:element name="ele1" type="xs:string"/>
<xs:element name="ele2" type="xs:string"/>
<xs:element name="ele3" type="xs:string"/>
<xs:element name="ele4" type="xs:string"/>
</xs:sequence>
</xs:complexType>
</xs:element>
如果你从这个 xsd 创建一个 XML,它看起来像这样:
If you create an XML from this xsd then, it will look something like this:
<compElement>
<ele1>First</ele1>
<ele2>Second</ele2>
<ele3>Third</ele3>
<ele4>Fourth</ele4>
</compElement>
所有示例:
<xs:element name="compElement">
<xs:complexType>
<xs:all>
<xs:element name="ele1" type="xs:string"/>
<xs:element name="ele2" type="xs:string"/>
<xs:element name="ele3" type="xs:string"/>
<xs:element name="ele4" type="xs:string"/>
</xs:all>
</xs:complexType>
</xs:element>
如果你从这个 xsd 创建一个 XML 文件,那么它可能看起来像这样:
If you create an XML file from this xsd then it could look something like this:
<compElement>
<ele2>Second</ele2>
<ele1>First</ele1>
<ele4>Fourth</ele4>
<ele3>Third</ele3>
</compElement>
更多信息关于 xsd:all
更多信息关于 xsd:sequence
More info on xsd:all
More Info on xsd:sequence
希望我回答了你的问题.
Hope I answered your question.
这篇关于<xsd:all> 之间的区别和 <xsd:sequence>在模式定义中?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!