Reputation: 623
I want to validate my XML file having XSD schemas. I use:
var settings = new XmlReaderSettings();
settings.ValidationFlags = XmlSchemaValidationFlags.AllowXmlAttributes
| XmlSchemaValidationFlags.ProcessIdentityConstraints
| XmlSchemaValidationFlags.ProcessInlineSchema
| XmlSchemaValidationFlags.ReportValidationWarnings;
settings.ValidationType = ValidationType.Schema;
settings.ValidationEventHandler += new ValidationEventHandler(settings_ValidationEventHandler);
settings.Schemas.Add(xsc);
var vreader = XmlReader.Create(stream, settings);
while (vreader.Read());
And if some error occured then I have beautiful human-readable information in my handler. But I want to know the node which caused the error. There is no access to object like XmlElement or something like this. Is there a way to do it?
Upvotes: 3
Views: 276
Reputation: 21638
I am not aware of an easy way on how to do this... I would start by looking at the SchemaInfo property associated with a node; intuitively, depending on the error, you might not get it at all...
The only other "key" between these might be the line/col number, which then can be cross indexed (you need to read this then, is using Xml.Linq).
Upvotes: 1