I am trying to construct a custom Error Message for unsuccessful XML validation using the callback validation event. I noticed that the sender object of the element is XMLReader and i got the Element or current Node name from ((XmlReader)sender).Name and exeception message from ValidationEventargs.Exception.Message. I trying to build the path of the current node failing in the validation by getting the parent nodes of the current node
Given below is the code snippet
XmlReaderSettings xrs = new XmlReaderSettings();
xrs.ValidationEventHandler += new ValidationEventHandler(ValidationEvent);
public void ValidationEvent(object sender, ValidationEventArgs e)
{
XmlReader xe = (XmlReader)sender;
ValidationError ve = new ValidationError();
ErrorElement = xe.Name;
ErrorMessage = e.Exception.Message;
ErrorPath = ""\\want to build the Node path
}