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

ZURINETAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Miguel OzSoftware EngineerCommented:
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.
0
guru_samiCommented:
- Define the string outside of the method.
string   varErrorMesages = String.Empty;

Open in new window

- Inside the method you just keep adding to the string.
varErrorMesages += String.Format("Line: {0}, Position: {1} \"{2}\"",e.Exception.LineNumber, e.Exception.LinePosition,e.Exception.Message);

Open in new window

0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
anarki_jimbelSenior DeveloperCommented:
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.
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
C#

From novice to tech pro — start learning today.