如何从XmlValidatingReader的ValidationEventHandler中的XmlSchemaException获取节点名称和值? [英] How to get node name and value from XmlSchemaException in the ValidationEventHandler of the XmlValidatingReader?

查看:71
本文介绍了如何从XmlValidatingReader的ValidationEventHandler中的XmlSchemaException获取节点名称和值?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我像这样设置我的Xml验证...

I set up my Xml validation like this...

XmlTextReader xrdr = new XmlTextReader(tempFile);
XmlValidatingReader xvr = new XmlValidatingReader(xrdr);
xvr.ValidationType = ValidationType.Schema;
xvr.ValidationEventHandler += new ValidationEventHandler(FormValidationEventHandler);
while (xvr.Read())
{
}



我的FormValidationEventHandler(object sender,ValidationEventArgs args)事件处理程序只是试图为用户捕获最有意义的消息,该消息应包括发生故障的Xml节点的名称和值以及异常消息.但是,在事件处理程序中暂停调试器时,仅内部变量$ exception包含消息中的特定节点值. args.Message和args.Exception.Message都只包含节点名称,这不够有用.我已经探究了发送方和args的所有属性和方法,但没有找到.

这是当前可用消息的示例...

"http://www.sec.gov/edgar/nmfpsecurities:InvestmentIssuer"元素根据其数据类型具有无效值."

这是$ exception中消息的示例...

根据其模式类型"http://www.sec.gov/edgar/invest:InvestmentIssuer"-换行(#xA),"EI DU PONT DE NEMOURS& CO."值无效或".xs:token"中不允许使用制表符(#x9)或制表符(#x9),前导或尾随空格以及一个或多个空格序列(#x20)."

我需要知道如何1)在给定发送者和参数的情况下访问失败的节点值,或2)在事件处理程序中神奇地访问内部变量$ exception.谢谢!



And my FormValidationEventHandler(object sender, ValidationEventArgs args) event handler is simply trying to capture the most meaningful message for the user, which should include the failing Xml node''s name and value, along with the exception message. However, when pausing the debugger in the event handler, only the internal variable $exception contains the specific node value in the message. The args.Message and args.Exception.Message both contain only the node name, which is not helpful enough. I have explored all the properties and methods of the sender and args, but have not found it.

Here is an example of the message currently available...

"The ''http://www.sec.gov/edgar/nmfpsecurities:InvestmentIssuer'' element has an invalid value according to its data type."

Here is an example of the message in $exception...

"The value ''E.I. DU PONT DE NEMOURS & CO. '' is invalid according to its schema type ''http://www.sec.gov/edgar/invest:InvestmentIssuer'' - line-feed (#xA) or tab (#x9) characters, leading or trailing spaces and sequences of one or more spaces (#x20) are not allowed in ''xs:token''."

I need to know how to either 1) access the failing node value given the sender and args, or 2) magically access the internal variable $exception inside my event handler. Thanks!

推荐答案

异常包含消息中的特定节点值. args.Message和args.Exception.Message都仅包含节点名称,这不够有用.我已经探究了发送方和args的所有属性和方法,但没有找到.

这是当前可用消息的示例...

"http://www.sec.gov/edgar/nmfpsecurities:InvestmentIssuer"元素根据其数据类型具有无效值."

这是
exception contains the specific node value in the message. The args.Message and args.Exception.Message both contain only the node name, which is not helpful enough. I have explored all the properties and methods of the sender and args, but have not found it.

Here is an example of the message currently available...

"The ''http://www.sec.gov/edgar/nmfpsecurities:InvestmentIssuer'' element has an invalid value according to its data type."

Here is an example of the message in


例外中的消息示例...

根据其模式类型"http://www.sec.gov/edgar/invest:InvestmentIssuer"-换行(#xA),"EI DU PONT DE NEMOURS& CO."值无效或".xs:token"中不允许使用制表符(#x9)或制表符(#x9),前导或尾随空格以及一个或多个空格序列(#x20)."

我需要知道如何1)在给定发送者和参数的情况下访问失败的节点值,或2)在事件处理程序中神奇地访问内部变量
exception...

"The value ''E.I. DU PONT DE NEMOURS & CO. '' is invalid according to its schema type ''http://www.sec.gov/edgar/invest:InvestmentIssuer'' - line-feed (#xA) or tab (#x9) characters, leading or trailing spaces and sequences of one or more spaces (#x20) are not allowed in ''xs:token''."

I need to know how to either 1) access the failing node value given the sender and args, or 2) magically access the internal variable


异常.谢谢!


这篇关于如何从XmlValidatingReader的ValidationEventHandler中的XmlSchemaException获取节点名称和值?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆