使用XmlSchemaValidator验证XmlElement,当xsi:nil=true时,使用专门的重载方法
来源:互联网 发布:中超球员数据库 编辑:程序博客网 时间:2024/06/06 06:51
当一个元素定义为可空nillable=true, 实际Xml节点xsi:nil=true, 验证时还是报内容无效,不能为空。
_validator.ValidateEndElement(null);
http://connect.microsoft.com/VisualStudio/feedback/details/97503/xmlschemavalidator-incorrectly-allows-xsi-nil-true-on-an-element-whose-nillable-is-false
Q:
XmlSchemaValidator should not allow xsi:nil="true" on those xs:element whose nillable is false.
I tried some. 1) setting IsNil = true on XmlSchemaInfo which is being passed to ValidateElement() and so on. 2) call ValidateAttribute() with "nil" as localName and XmlSchema.InstanceNamespace as namespace URI.
A:
Thank you very much for your feedback. The issue you are running into is that nillabiliy is a constraint on the element not on the xsi:nill attribute itself. To validate the the element is appropriately set to nil or not you can use the overloaded ValidateElement method:
void ValidateElement(string localName, string namespaceURI, XmlSchemaInfo schemaInfo, string xsiType, string xsiNil, string xsiSchemaLocation, string xsiNoNamespaceSchemaLocation);
Validating the attribute xsi:nil is really just verifying whether one of the correct values of nil were provided.
Here is a background comment from a developer on this:
This is because, the value of the xsi attributes can even change the declaration we look up for the element. For example, xsi:type attribute can change the type of the element to a sub or super type. Even though xsi:nil does not change the element declaration, to be consistent, all xsi attribute processing is done via this overload and subsequent ValdiateAttribute calls on the xsi:attributes are ignored.
Thanks you again for this feedback. I will flag this bug for documentation to try to make the api clearer in this area. Thanks for your help!
- 使用XmlSchemaValidator验证XmlElement,当xsi:nil=true时,使用专门的重载方法
- xsi:nil="true"
- XML解析之xsi:nil="true"
- c#设置xml内容不换行;添加属性为xsi:nil="true"的空节点
- XML解析之xsi:nil="true"(续)
- c#设置xml空节点不换行;添加属性为xsi:nil="true"的空节点
- Capybara 当使用 :js => true 时无法工作的问题
- javascript中使用ajax异步验证数据库后方法return true时总是返回undefined
- xsi:noNamespaceSchemaLocation使用心得
- XML i:nil="true"
- Android使用toolbar设置了fitSystemWindows = “true”的时候当edittext弹出了软键盘时toolbar被拉伸的问题
- requestDisallowInterceptTouchEvent(true)的使用
- @DynamicUpdate(true) @DynamicInsert(true)使用的环境
- hibernate中inverse=true的使用
- iphone开发cocoa中nil,NSNull,Nil的使用区别
- ios Nil nil NULL NSNull的区别和使用
- iOS开发-nil/Nil/NULL/NSNull 的使用
- 后台数据验证时使用的方法
- 硬件加速CoolUI 1.0---【状态更新,CodeSize】
- [转]八大排序算法总结
- 超赞的多媒体和网络应用图标
- OS X: Time Machine错误(code=-41)?
- 一名优秀的Flex开发者需要知道的10样东西
- 使用XmlSchemaValidator验证XmlElement,当xsi:nil=true时,使用专门的重载方法
- C# 将数据导出到Execl汇总
- C#调用Excel VBA宏
- win2003 域 更改密码策略
- 更改密码策略设置 windows
- eclipse中实现代码提示功能
- 总结Struts2的工作原理
- 2011-06-16 | 三角路考场 | 科目二顺利通过
- 【转】《 磁道、扇区和柱面 》