根元素 minOccurs 或 maxOccurs [英] Root element minOccurs or maxOccurs
问题描述
在 XSD 中...
是否允许在 minOccurs="0" maxOccurs="1" 的根元素旁边写入?像下面
Is it allowed to write beside a root element with minOccurs="0" maxOccurs="1" ? like below
<?xml version="1.0" encoding="UTF-8" ?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">
<xs:element name="shiporder" minOccurs="0" maxOccurs="1">
<xs:complexType>
<xs:sequence>
........
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:schema>
过去允许这样做吗?
推荐答案
否. minOccurs
或 maxOccurs
没有意义出现在验证根上,因为格式良好的 XML 必须有一个根元素:
No. It would not make sense for minOccurs
or maxOccurs
to appear on a validation root because well-formed XML must have a single root element:
[定义:只有一个元素,称为根,或者文档元素,它的任何部分都没有出现在任何其他的内容中]
[Definition: There is exactly one element, called the root, or document element, no part of which appears in the content of any other element.]
如何在根级别表达可选性
可以有多个顶级元素声明,这可能是您使用 minOccurs="0"
所追求的效果:
<?xml version="1.0" encoding="UTF-8" ?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">
<xs:element name="shiporder">
...
</xs:element>
<xs:element name="e2">
...
</xs:element>
<xs:element name="e3">
...
</xs:element>
</xs:schema>
这表示根元素可以是 shiporder
或 e2
或 e3
.
This represents that the root element could be shiporder
or e2
or e3
.
要允许多个发货订单,请将它们包装在一个容器中,shiporders
,元素:
To allow multiple ship orders, wrap them in a single container, shiporders
, element:
<?xml version="1.0" encoding="UTF-8" ?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">
<xs:element name="shiporders">
<xs:complexType>
<xs:sequence>
<xs:element name="shiporder" minOccurs="0" maxOccurs="unbounded">
...
</xs:element>
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:schema>
这篇关于根元素 minOccurs 或 maxOccurs的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!