LINQ to XML 不返回默认值
我在 XSD 中指定了一个默认值,如下所示:
<xs:complexType name="image">
<xs:attribute name="path" type="xs:string" />
<xs:attribute name="type" type="imageType" default="normal" />
</xs:complexType>
但是,除非我在 XML 中显式包含一个值,否则当我运行如下所示的 LINQ 查询时,“类型”始终作为空字符串返回:
Dim images = From i In collection.<image> Select i.@path, i.@type
这是预期的结果还是可能的情况省略该属性并让 LINQ 检查默认值?
I have a default value specified in XSD as follows:
<xs:complexType name="image">
<xs:attribute name="path" type="xs:string" />
<xs:attribute name="type" type="imageType" default="normal" />
</xs:complexType>
But unless I explicitly include a value in the XML, 'type' is always returned as an empty string when I run a LINQ query such as this:
Dim images = From i In collection.<image> Select i.@path, i.@type
Should this be expected or is it possible to omit the attribute and let LINQ check for a default value?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
那么,您是否首先根据您的架构验证输入 XML?
下面是一个示例:
模式为
,XML 输入为
示例输出
Well do you first validate the input XML against your schema?
Here is an example:
With the schema being
and the XML input being
that sample outputs