// Create an XmlReaderSettings object and load the schema into it. // This will also load in any imported/included schemas. XmlReaderSettings settings = new XmlReaderSettings(); settings.ValidationType = ValidationType.Schema; settings.ValidationFlags = XmlSchemaValidationFlags.ProcessSchemaLocation; settings.Schemas.Add(null, reader); // Setup the event handler to handle errors/warnings settings.ValidationEventHandler += new ValidationEventHandler(settings_ValidationEventHandler); // Get the list of all targetNamespaces from the loaded schemas List<string> namespaces = new List<string>(); foreach (XmlSchema s in settings.Schemas.Schemas()) { if (!string.IsNullOrEmpty(s.TargetNamespace)) { namespaces.Add(s.TargetNamespace); } } // Load the current Xml Document into a stream MemoryStream stream = new MemoryStream(); instanceDoc.Save(stream); stream.Position = 0L; // Create the validating reader XmlReader vr = XmlReader.Create(stream, settings); // Read the document stream - this will validate as it reads while (vr.Read()) { }
var
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)