XSD.exe 不强制执行 minOccurs

发布于 2024-08-31 06:59:35 字数 153 浏览 1 评论 0原文

我有一个简单的架构,其中我将 minOccurs 和 maxOccurs 声明为 1。当我运行 XSD.exe 生成 C# 类并在代码中使用该类时;该字段不是强制执行的。是否缺少一些额外的步骤?或者使用 XSD.exe 生成的类是否没有必填字段?

任何建议或见解都会有所帮助。

I have a simple schema where I'm declaring both minOccurs and maxOccurs to 1. When I run the XSD.exe to generate a C# class and consume the class in code; the field is not enforced as mandatory. Is there some additional step missing? or does the classes generated using XSD.exe don't mandatory fields?

any suggestions or insight will be helpful.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

愚人国度 2024-09-07 06:59:35

就像 Visual Studio 中的 Xml/infer schema 工具一样,每当我使用 XSD.exe 时,我都会修复一些生成的代码。 XSD.exe 进行了很好的近似,但它并不完全有效。

minOccurs / maxOccurs 'bug' 记录在MSDN。

从生成源代码时
XML 架构文档,Xsd.exe 忽略
minOccurs 属性应用于
<选择>、<序列>,<组>,<所有>,
且<任何>元素。

对于元素,Xsd.exe
忽略 minOccurs 属性,如果
maxOccurs 属性的值为
大于 1,或无界。在这个
在这种情况下,该工具会生成一个数组
XSD数据对应的类型
类型。 Xsd.exe 使用的值
maxOccurs属性来确定
是否生成单个实例
或数组。

对于元素,Xsd.exe
还忽略 minOccurs 属性
如果它应用于模式数据类型
转换为 .NET Framework
参考类型。

仅当满足以下所有条件时
是真的 Xsd.exe 使用
minOccurs 属性的值:

涉及到该元素。

maxOccurs 属性规定了
单实例。

数据类型转换为值
类型。

Like the Xml / infer schema tool in visual studio, whenever I've used XSD.exe I've ended up fixing some of the generated code. XSD.exe does a good approximation but it doesn't work entirely.

The minOccurs / maxOccurs 'bug' is documented on MSDN.

When generating source code from an
XML Schema document, Xsd.exe ignores
the minOccurs attribute applied to the
< choice >, < sequence >, < group >, < all >,
and < any > elements.

For the element, Xsd.exe
ignores the minOccurs attribute if the
value of the maxOccurs attribute is
greater than 1, or unbounded. In this
case, the tool produces an array of
the type corresponding to the XSD data
type. Xsd.exe uses the value of the
maxOccurs attribute to determine
whether to produce a single instance
or an array.

For the element, Xsd.exe
also ignores the minOccurs attribute
if it is applied to a schema data type
that converts to a .NET Framework
reference type.

Only when all the following conditions
are true does Xsd.exe utilize the
value of the minOccurs attribute:

The element is involved.

The maxOccurs attribute dictates a
single instance.

The data type converts to a value
type.

你的呼吸 2024-09-07 06:59:35

如何在代码中强制执行任意小事件?某种断言?我猜你只能映射到“不可为空的单个实例”(1:1)不可为空的数组(1:many)及其可空的等价物(0;1)和(0:many)

How would you enforce an arbitrary minoccurs in code? Some sort of assertions? I guess you can only map to "Non-nullable single instance" (1:1) non-nullable array (1:many) and their nullable equivalents (0;1), and (0:many)

离不开的别离 2024-09-07 06:59:35

您是正确的,XSD.EXE 不强制执行出现要求。这是设计好的。

You are correct that XSD.EXE does not enforce occurrence requirements. This is as designed.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文