internal static void Preprocess(XmlSchema schema) { if (!schema.IsPreprocessed) { try { XmlNameTable nameTable = new Microsoft.Xml.NameTable(); Preprocessor prep = new Preprocessor(nameTable, new SchemaNames(nameTable), null); prep.SchemaLocations = new Hashtable(); prep.Execute(schema, schema.TargetNamespace, false); } catch (XmlSchemaException e) { throw CreateValidationException(e, e.Message); } } }
/// <include file='doc\XmlSchemas.uex' path='docs/doc[@for="XmlSchemas.Compile"]/*' /> public void Compile(ValidationEventHandler handler, bool fullCompile) { if (_isCompiled) { return; } foreach (XmlSchema s in delayedSchemas.Values) { Merge(s); } delayedSchemas.Clear(); if (fullCompile) { _schemaSet = new XmlSchemaSet(); _schemaSet.XmlResolver = null; _schemaSet.ValidationEventHandler += handler; foreach (XmlSchema s in References.Values) { _schemaSet.Add(s); } int schemaCount = _schemaSet.Count; foreach (XmlSchema s in List) { if (!SchemaSet.Contains(s)) { _schemaSet.Add(s); schemaCount++; } } if (!SchemaSet.Contains(XmlSchema.Namespace)) { AddReference(XsdSchema); _schemaSet.Add(XsdSchema); schemaCount++; } if (!SchemaSet.Contains(XmlReservedNs.NsXml)) { AddReference(XmlSchema); _schemaSet.Add(XmlSchema); schemaCount++; } _schemaSet.Compile(); _schemaSet.ValidationEventHandler -= handler; _isCompiled = _schemaSet.IsCompiled && schemaCount == _schemaSet.Count; } else { try { XmlNameTable nameTable = new Microsoft.Xml.NameTable(); Preprocessor prep = new Preprocessor(nameTable, new SchemaNames(nameTable), null); prep.XmlResolver = null; prep.SchemaLocations = new Hashtable(); prep.ChameleonSchemas = new Hashtable(); foreach (XmlSchema schema in SchemaSet.Schemas()) { prep.Execute(schema, schema.TargetNamespace, true); } } catch (XmlSchemaException e) { throw CreateValidationException(e, e.Message); } } }