<all> 之间的区别<序列><选择>和<组>在 XSD 中?
问题描述:
在 XML 模式中?
What is the difference between <all> <sequence> <choice> and <group>
in XML Schema?
答
何时使用 xsd:all
, xsd:sequence
, xsd:choice代码>,或
xsd:group
:
When to use xsd:all
, xsd:sequence
, xsd:choice
, or xsd:group
:
- 当所有子元素都必须存在时使用
xsd:all
订购. - 使用
xsd:sequence
当子元素必须按照它们的顺序存在时发生限制和顺序很重要. - 当必须存在子元素之一时使用
xsd:choice
. - 使用
xsd:group
作为包装上述任何一项的方式,以便命名并在 XSD 内的多个位置重复使用.
- Use
xsd:all
when all child elements must be present, independent of order. - Use
xsd:sequence
when child elements must be present per their occurrence constraints and order does matters. - Use
xsd:choice
when one of the child element must be present. - Use
xsd:group
as a way to wrap any of the above in order to name and reuse in multiple locations within an XSD.
请注意,除了子元素之外,出现约束还可以出现在 xsd:all
、xsd:sequence
或 xsd:choice
上实现各种基数效果.
Note that occurrence constraints can appear on xsd:all
, xsd:sequence
, or xsd:choice
in addition to the child elements to achieve various cardinality effects.