KnowledgeHub
Questions
Tags
Users
Search
Alex Rivera
|
Logout
Edit Question
Title
Body
Let's say I have a schema with which I want an input document to comply. I load the file according to the schema like this: // Load the ABC XSD var schemata = new XmlSchemaSet(); string abcSchema = FooResources.AbcTemplate; using (var reader = new StringReader(abcSchema)) using (var schemaReader = XmlReader.Create(reader)) { schemata.Add(string.Empty, schemaReader); } // Load the ABC file itself var settings = new XmlReaderSettings { CheckCharacters = true, CloseInput = false, ConformanceLevel = ConformanceLevel.Document, IgnoreComments = true, Schemas = schemata, ValidationType = ValidationType.Schema, ValidationFlags = XmlSchemaValidationFlags.ReportValidationWarnings }; XDocument inputDoc; try { using (var docReader = XmlReader.Create(configurationFile, settings)) { inputDoc = XDocument.Load(docReader); } } catch (XmlSchemaException xsdViolation) { throw new InvalidDataException(".abc file format constraint violated.", xsdViolation); } This works fine in detecting trivial errors in the file. However, because the schema is locked to a namespace, a document like the following is invalid, but sneaks through: <badDoc xmlns="http://Foo/Bar/Bax"> This is not a valid document; but Schema doesn't catch it because of that xmlns in the badDoc element. </badDoc> I would like to say that only the namespaces for which I have schemata should pass schema validation.
Tags (comma-separated)
Save Edits
Cancel