Avatar of ZURINET
ZURINET

asked on 

ValidationEventArgs e to String

Hi all
I have the code below , which  outputs the result of an xml Validaton.

The result print out 3 error position..
But the string   varErrorMesages displays only one ..
How can I assign all the error messages to string.. and not just the last value.
I want to pass all the string generated by the error to the string varErrorMesages

 static void inputXMLValidationEventHandler(object sender, ValidationEventArgs e)
                          {
                              if (e.Severity == XmlSeverityType.Warning)
                              {
                                  Debug.Write("WARNING in XML Messages:  ");
                                  Debug.WriteLine(e.Message);
                                 string   varErrorMesages = String.Format("Line: {0}, Position: {1} \"{2}\"",e.Exception.LineNumber, e.Exception.LinePosition,e.Exception.Message);

WARNING in XML Messages:  Could not find schema information for the element 'doc'.
WARNING in XML Messages:  Could not find schema information for the element 'assembly'.
WARNING in XML Messages:  Could not find schema information for the element 'name'.
WARNING in XML Messages:  Could not find schema information for the element 'members'.

Open in new window

C#ASP.NET.NET Programming

Avatar of undefined
Last Comment
Dmitry G
Avatar of Miguel Oz
Miguel Oz
Flag of Australia image

Be aware that it may not be an exception associated with the validation object e.
Debug.WriteLine(e.Message) is using e.Message while varErrorMesages  is capturing e.Exception errors.
I wil suggest that you capture both e.Message and exception info in varErrorMesages.
ASKER CERTIFIED SOLUTION
Avatar of guru_sami
guru_sami
Flag of United States of America image

Blurred text
THIS SOLUTION IS ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
Avatar of Dmitry G
Dmitry G
Flag of New Zealand image

Your handler is invoked three times, for three different errors. Therefore the only way you can achieve what you want by creating a class level variable.

See guru_sami's comment.
.NET Programming
.NET Programming

The .NET Framework is not specific to any one programming language; rather, it includes a library of functions that allows developers to rapidly build applications. Several supported languages include C#, VB.NET, C++ or ASP.NET.

137K
Questions
--
Followers
--
Top Experts
Get a personalized solution from industry experts
Ask the experts
Read over 600 more reviews

TRUSTED BY

IBM logoIntel logoMicrosoft logoUbisoft logoSAP logo
Qualcomm logoCitrix Systems logoWorkday logoErnst & Young logo
High performer badgeUsers love us badge
LinkedIn logoFacebook logoX logoInstagram logoTikTok logoYouTube logo