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

8/22/2022 - Mon
Miguel Oz

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
guru_sami

Log in or sign up to see answer
Become an EE member today7-DAY FREE TRIAL
Members can start a 7-Day Free trial then enjoy unlimited access to the platform
Sign up - Free for 7 days
or
Learn why we charge membership fees
We get it - no one likes a content blocker. Take one extra minute and find out why we block content.
See how we're fighting big data
Not exactly the question you had in mind?
Sign up for an EE membership and get your own personalized solution. With an EE membership, you can ask unlimited troubleshooting, research, or opinion questions.
ask a question
Dmitry G

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.
All of life is about relationships, and EE has made a viirtual community a real community. It lifts everyone's boat
William Peck