1

I want to validate an XML against a schema and set certain validation flags. I know that I can set ValidationFlags when validating an XML stream like so:

var settings = new XmlReaderSettings { 
  Schemas = schemas;
  ValidationFlags = ...; // HERE
};
settings.ValidationEventHandler += MyValidationErrorHandler;

using(var stream = ...)
{
    var reader = XmlReader.Create(stream, settings);
    XDocument.Load(reader);
}

However, if I already have an existing XDocument, the MSDN says I should validate like so:

myDoc.Validate(schemas, MyValidationErrorHandler);

But how to set the ValidationFlags in this scenario?

D.R.
  • 20,268
  • 21
  • 102
  • 205
  • 1
    Does this help at all? https://stackoverflow.com/questions/17232575/xdocument-validate-is-always-successful – claylong Dec 07 '17 at 15:53
  • 2
    I guess you have to call `myDoc.CreateReader()`, then modify settings of that reader and validate using it – Evk Dec 07 '17 at 15:55
  • 1
    I agree with @Evk, the suggested way of using flags for validation appears to be a Reader. – claylong Dec 07 '17 at 15:59

0 Answers0