xml XSD maxOccurs="无界"
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/1165845/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
XSD maxOccurs="unbounded"
提问by JL.
I have generated an XSD file from an XML snippet using xsd.exe /out
我已经使用 XML 片段生成了一个 XSD 文件 xsd.exe /out
What its done is created maxOccurs="unbounded"properties for certain elements.
它所做的是maxOccurs="unbounded"为某些元素创建属性。
If I only want the element to appear once, and not be a collection do I set the maxOccurs like this?
如果我只希望元素出现一次,而不是一个集合,我应该像这样设置 maxOccurs 吗?
maxOccurs="1"
maxOccurs="1"
回答by Nick Bastin
Yes. Of course, keep in mind that maxOccurs is really maximum occurances - there can still be zero. If you want there to always be one, you'll need minOccurs="1" as well.
是的。当然,请记住 maxOccurs 实际上是最大出现次数 - 仍然可以为零。如果您希望始终有一个,则还需要 minOccurs="1"。
回答by Welbog
Yes, that's how it's done.
是的,就是这样做的。
maxOccurslimits the maximum number of repetitions of a given element that can appear.
maxOccurs限制可以出现的给定元素的最大重复次数。
Similarly, minOccurslimits the minimum number of repetitions.
同样,minOccurs限制最小重复次数。
They're called occurrence indicators. You can read more about them at W3Schools.
它们被称为发生指标。您可以在 W3Schools 上阅读有关它们的更多信息。
回答by Erik Svensson
http://www.w3schools.com/schema/schema_example.aspsays that: "The default value for both maxOccurs and minOccurs is 1!"
http://www.w3schools.com/schema/schema_example.asp说:“maxOccurs 和 minOccurs 的默认值都是 1!”

