System.Xml.Schema.Preprocessor.Execute C# (CSharp) Méthode

Execute() public méthode

public Execute ( XmlSchema schema, string targetNamespace, bool loadExternals ) : bool
schema XmlSchema
targetNamespace string
loadExternals bool
Résultat bool
        public bool Execute(XmlSchema schema, string targetNamespace, bool loadExternals) {
            rootSchema = schema; //Need to lock main schema here
            Xmlns = NameTable.Add("xmlns");
            NsXsi = NameTable.Add(XmlReservedNs.NsXsi);

            rootSchema.ImportedSchemas.Clear();
            rootSchema.ImportedNamespaces.Clear();

            //Add root schema to the schemaLocations table
            if (rootSchema.BaseUri != null) {
                if (schemaLocations[rootSchema.BaseUri] == null) {
                    schemaLocations.Add(rootSchema.BaseUri, rootSchema);
                } 
            }
            //Check targetNamespace for rootSchema
            if (rootSchema.TargetNamespace != null) {
                if (targetNamespace == null) {
                    targetNamespace = rootSchema.TargetNamespace;
                }
                else if (targetNamespace != rootSchema.TargetNamespace) {
                    SendValidationEvent(Res.Sch_MismatchTargetNamespaceEx, targetNamespace, rootSchema.TargetNamespace, rootSchema);
                }
            }
            else if (targetNamespace != null && targetNamespace.Length != 0) { //if schema.TargetNamespace == null & targetNamespace != null, we will force the schema components into targetNamespace
                rootSchema = GetChameleonSchema(targetNamespace, rootSchema); //Chameleon include at top-level
            }
            if (loadExternals && xmlResolver != null) {
                LoadExternals(rootSchema);
            }
            BuildSchemaList(rootSchema);
            int schemaIndex = 0;
            XmlSchema listSchema;
            try {
                //Accquire locks on all schema objects; Need to lock only on pre-created schemas and not parsed schemas
                for (schemaIndex = 0; schemaIndex < lockList.Count; schemaIndex++) {
                    listSchema = (XmlSchema)lockList.GetByIndex(schemaIndex);
                    Monitor.Enter(listSchema); 
                    listSchema.IsProcessing = false; //Reset processing flag from LoadExternals
                }
                //Preprocess
                rootSchemaForRedefine = rootSchema;
                Preprocess(rootSchema, targetNamespace, rootSchema.ImportedSchemas);
                if (redefinedList != null) { //If there were redefines
                    foreach (RedefineEntry redefineEntry in redefinedList) {
                        PreprocessRedefine(redefineEntry);
                    }
                }
            }
            finally { //Releasing locks in finally block
                if (schemaIndex == lockList.Count) {
                    schemaIndex--;
                }
                
                for (int i = schemaIndex; schemaIndex >= 0; schemaIndex--) {
                    listSchema = (XmlSchema)lockList.GetByIndex(schemaIndex);
                    listSchema.IsProcessing = false; //Reset processing flag from Preprocess
                    if (listSchema == Preprocessor.GetBuildInSchema()) { //dont re-set compiled flags for xml namespace schema
                        Monitor.Exit(listSchema);
                        continue;
                    }
                    listSchema.IsCompiledBySet = false;
                    listSchema.IsPreprocessed = !HasErrors;
                    Monitor.Exit(listSchema); //Release locks on all schema objects
                }
            }
            rootSchema.IsPreprocessed = !HasErrors; //For chameleon at top-level
            return !HasErrors;
        }
        

Usage Example

 internal bool PreprocessSchema(ref XmlSchema schema, string targetNamespace) {
     Preprocessor prep = new Preprocessor(nameTable, GetSchemaNames(nameTable), eventHandler, compilationSettings);
     prep.XmlResolver = readerSettings.GetXmlResolver();
     prep.ReaderSettings = readerSettings;
     prep.SchemaLocations = schemaLocations;
     prep.ChameleonSchemas = chameleonSchemas;
     bool hasErrors = prep.Execute(schema, targetNamespace, true);
     schema = prep.RootSchema; //For any root level chameleon cloned
     return hasErrors;
 }
All Usage Examples Of System.Xml.Schema.Preprocessor::Execute