Link to home
Start Free TrialLog in
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

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

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
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.