xsd 类型=“anySimpleType”对于属性

发布于 2025-01-05 20:58:57 字数 458 浏览 0 评论 0原文

如果这是一个愚蠢的问题,我很抱歉,到目前为止我还没有真正对 xml 做过任何事情。

我希望能够将一些 xml 反序列化到具有 object 类型属性的类中。此属性可以是 intguidstring。在 xml 中,我希望将此属性定义为属性。我本希望我的 xsd 看起来像这样:

<xsd:complexType name="MyClass">
  <xsd:attribute name="MyProperty" type="xsd:anySimpleType" />
</xsd:complexType>

但是,Visual Studio intellisense 没有列出选项“xsd:anySimpleType”。这是智能感知的问题还是我在做一些本质上错误的事情?

Apologies if this is a silly question, I haven't really done anything with xml up until now.

I want to be able to deserialise some xml into a class that has a property of type object. This property could be an int, guid or a string. In the xml I would like this property to be defined as an attribute. I would have expected my xsd to look something like this:

<xsd:complexType name="MyClass">
  <xsd:attribute name="MyProperty" type="xsd:anySimpleType" />
</xsd:complexType>

However, visual studio intellisense doesn't list the option, "xsd:anySimpleType". Is this an issue with intellisense or am I doing something inherently wrong?

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

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

发布评论

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

评论(2

潦草背影 2025-01-12 20:58:57

尽管拥有 xs:anySimpleType 类型的属性是合法的,但我会避免使用它并改用 xs:string。这是因为该规范留下了许多关于此类属性应如何表现的问题。不可能使用枚举或正则表达式来限制它,如果在身份约束等中使用它,则很难定义会发生什么。验证与 xs:string 完全相同,但行为的其他方面是相当奇怪,并且可能因实现而异。

有人可能会说,如果您稍后想要定义字符串、整数和 URI 等子类型,那么 xs:anySimpleType 是有意义的。但这是我能想到的唯一赞成的情况。

Although it's legal to have an attribute of type xs:anySimpleType, I would avoid it and use xs:string instead. This is because the spec leaves many questions open about how such an attribute should behave. It's not possible to restrict it using an enumeration or a regular expression, it's very poorly defined what happens if you use it in an identity constraint, etc. The validation is exactly the same as for xs:string, but other aspects of the behaviour are fairly weird and likely to vary between implementations.

One could argue that xs:anySimpleType makes sense if you want later to define subtypes such as string, int, and URI. But that's the only case I can think of in favour.

他夏了夏天 2025-01-12 20:58:57

xsd:anySimpleType(和 xsd:anyType)是特殊的所谓 ur-type 定义(前者是简单的 ur-type);顺便说一句,当谈到 XSD 数据类型时,我总是指出这张图< /a>.

我相信正是由于这种特殊性,这些类型没有出现在 Intellisense 中的部分原因。我想另一个原因也是它是默认分配的类型;换句话说,对于您的属性,如果您不设置类型,则无论如何它都将是anySimpleType。

然而,我也承认这个解释不适用于其他编辑器 - Eclipse 就是其中之一;您可以在 Intellisense 中获得所有这些类型,无需提出任何问题......

The xsd:anySimpleType (and xsd:anyType) are special so-called ur-type definitions (the former being the simple ur-type); incidentally, when it comes to XSD datatypes, I always point out this diagram.

Just being this special, I believe is part of the reason why these types don't show up in Intellisense. I guess another reason is also that it is the type assigned by default; in other words, for your attribute if you do not set the type, it will be anySimpleType regardless.

However, I also admit this explanation doesn't work with other editors - Eclipse being one of them; There you get all these types in Intellisense, no questions asked...

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