Beispiel #1
0
        /// <remarks>
        /// An Attribute group can only be defined as a child of XmlSchema or in XmlSchemaRedefine.
        /// The other attributeGroup has type XmlSchemaAttributeGroupRef.
        ///  1. Name must be present
        /// </remarks>
        internal override int Compile(ValidationEventHandler h, XmlSchema schema)
        {
            // If this is already compiled this time, simply skip.
            if (CompilationId == schema.CompilationId)
            {
                return(errorCount);
            }

            errorCount = 0;

            if (redefinedObject != null)
            {
                errorCount += redefined.Compile(h, schema);
                if (errorCount == 0)
                {
                    redefined = (XmlSchemaAttributeGroup)redefinedObject;
                }
            }

            XmlSchemaUtil.CompileID(Id, this, schema.IDCollection, h);

            if (this.Name == null || this.Name == String.Empty)            //1
            {
                error(h, "Name is required in top level simpletype");
            }
            else if (!XmlSchemaUtil.CheckNCName(this.Name))            // b.1.2
            {
                error(h, "name attribute of a simpleType must be NCName");
            }
            else
            {
                this.qualifiedName = new XmlQualifiedName(this.Name, AncestorSchema.TargetNamespace);
            }

            if (this.AnyAttribute != null)
            {
                errorCount += this.AnyAttribute.Compile(h, schema);
            }

            foreach (XmlSchemaObject obj in Attributes)
            {
                if (obj is XmlSchemaAttribute)
                {
                    XmlSchemaAttribute attr = (XmlSchemaAttribute)obj;
                    errorCount += attr.Compile(h, schema);
                }
                else if (obj is XmlSchemaAttributeGroupRef)
                {
                    XmlSchemaAttributeGroupRef gref = (XmlSchemaAttributeGroupRef)obj;
                    errorCount += gref.Compile(h, schema);
                }
                else
                {
                    error(h, "invalid type of object in Attributes property");
                }
            }
            this.CompilationId = schema.CompilationId;
            return(errorCount);
        }
 internal override int Compile(ValidationEventHandler h, XmlSchema schema)
 {
     if (this.CompilationId == schema.CompilationId)
     {
         return(0);
     }
     if (this.isRedefinedComponent)
     {
         if (base.Annotation != null)
         {
             base.Annotation.isRedefinedComponent = true;
         }
         if (this.AnyAttribute != null)
         {
             this.AnyAttribute.isRedefinedComponent = true;
         }
         foreach (XmlSchemaObject xmlSchemaObject in this.Attributes)
         {
             xmlSchemaObject.isRedefinedComponent = true;
         }
     }
     if (this.BaseTypeName == null || this.BaseTypeName.IsEmpty)
     {
         base.error(h, "base must be present, as a QName");
     }
     else if (!XmlSchemaUtil.CheckQName(this.BaseTypeName))
     {
         base.error(h, "BaseTypeName must be a QName");
     }
     if (this.BaseType != null)
     {
         this.errorCount += this.BaseType.Compile(h, schema);
     }
     if (this.AnyAttribute != null)
     {
         this.errorCount += this.AnyAttribute.Compile(h, schema);
     }
     foreach (XmlSchemaObject xmlSchemaObject2 in this.Attributes)
     {
         if (xmlSchemaObject2 is XmlSchemaAttribute)
         {
             XmlSchemaAttribute xmlSchemaAttribute = (XmlSchemaAttribute)xmlSchemaObject2;
             this.errorCount += xmlSchemaAttribute.Compile(h, schema);
         }
         else if (xmlSchemaObject2 is XmlSchemaAttributeGroupRef)
         {
             XmlSchemaAttributeGroupRef xmlSchemaAttributeGroupRef = (XmlSchemaAttributeGroupRef)xmlSchemaObject2;
             this.errorCount += xmlSchemaAttributeGroupRef.Compile(h, schema);
         }
         else
         {
             base.error(h, xmlSchemaObject2.GetType() + " is not valid in this place::SimpleContentRestriction");
         }
     }
     XmlSchemaUtil.CompileID(base.Id, this, schema.IDCollection, h);
     this.CompilationId = schema.CompilationId;
     return(this.errorCount);
 }
Beispiel #3
0
 internal override int Compile(ValidationEventHandler h, XmlSchema schema)
 {
     if (this.CompilationId == schema.CompilationId)
     {
         return(this.errorCount);
     }
     this.errorCount = 0;
     if (this.redefinedObject != null)
     {
         this.errorCount += this.redefined.Compile(h, schema);
         if (this.errorCount == 0)
         {
             this.redefined = (XmlSchemaAttributeGroup)this.redefinedObject;
         }
     }
     XmlSchemaUtil.CompileID(base.Id, this, schema.IDCollection, h);
     if (this.Name == null || this.Name == string.Empty)
     {
         base.error(h, "Name is required in top level simpletype");
     }
     else if (!XmlSchemaUtil.CheckNCName(this.Name))
     {
         base.error(h, "name attribute of a simpleType must be NCName");
     }
     else
     {
         this.qualifiedName = new XmlQualifiedName(this.Name, base.AncestorSchema.TargetNamespace);
     }
     if (this.AnyAttribute != null)
     {
         this.errorCount += this.AnyAttribute.Compile(h, schema);
     }
     foreach (XmlSchemaObject xmlSchemaObject in this.Attributes)
     {
         if (xmlSchemaObject is XmlSchemaAttribute)
         {
             XmlSchemaAttribute xmlSchemaAttribute = (XmlSchemaAttribute)xmlSchemaObject;
             this.errorCount += xmlSchemaAttribute.Compile(h, schema);
         }
         else if (xmlSchemaObject is XmlSchemaAttributeGroupRef)
         {
             XmlSchemaAttributeGroupRef xmlSchemaAttributeGroupRef = (XmlSchemaAttributeGroupRef)xmlSchemaObject;
             this.errorCount += xmlSchemaAttributeGroupRef.Compile(h, schema);
         }
         else
         {
             base.error(h, "invalid type of object in Attributes property");
         }
     }
     this.CompilationId = schema.CompilationId;
     return(this.errorCount);
 }
        /// <remarks>
        /// </remarks>
        internal override int Compile(ValidationEventHandler h, XmlSchema schema)
        {
            // If this is already compiled this time, simply skip.
            if (CompilationId == schema.CompilationId)
            {
                return(0);
            }

            if (this.isRedefinedComponent)
            {
                if (Annotation != null)
                {
                    Annotation.isRedefinedComponent = true;
                }
                if (AnyAttribute != null)
                {
                    AnyAttribute.isRedefinedComponent = true;
                }
                foreach (XmlSchemaObject obj in Attributes)
                {
                    obj.isRedefinedComponent = true;
                }
                if (Particle != null)
                {
                    Particle.isRedefinedComponent = true;
                }
            }

            if (BaseTypeName == null || BaseTypeName.IsEmpty)
            {
                error(h, "base must be present, as a QName");
            }
            else if (!XmlSchemaUtil.CheckQName(BaseTypeName))
            {
                error(h, "BaseTypeName is not a valid XmlQualifiedName");
            }

            if (this.AnyAttribute != null)
            {
                errorCount += AnyAttribute.Compile(h, schema);
            }

            foreach (XmlSchemaObject obj in Attributes)
            {
                if (obj is XmlSchemaAttribute)
                {
                    XmlSchemaAttribute attr = (XmlSchemaAttribute)obj;
                    errorCount += attr.Compile(h, schema);
                }
                else if (obj is XmlSchemaAttributeGroupRef)
                {
                    XmlSchemaAttributeGroupRef atgrp = (XmlSchemaAttributeGroupRef)obj;
                    errorCount += atgrp.Compile(h, schema);
                }
                else
                {
                    error(h, obj.GetType() + " is not valid in this place::ComplexConetnetExtension");
                }
            }

            if (Particle != null)
            {
                if (Particle is XmlSchemaGroupRef)
                {
                    errorCount += ((XmlSchemaGroupRef)Particle).Compile(h, schema);
                }
                else if (Particle is XmlSchemaAll)
                {
                    errorCount += ((XmlSchemaAll)Particle).Compile(h, schema);
                }
                else if (Particle is XmlSchemaChoice)
                {
                    errorCount += ((XmlSchemaChoice)Particle).Compile(h, schema);
                }
                else if (Particle is XmlSchemaSequence)
                {
                    errorCount += ((XmlSchemaSequence)Particle).Compile(h, schema);
                }
                else
                {
                    error(h, "Particle of a restriction is limited only to group, sequence, choice and all.");
                }
            }

            XmlSchemaUtil.CompileID(Id, this, schema.IDCollection, h);

            this.CompilationId = schema.CompilationId;
            return(errorCount);
        }
 internal override int Compile(ValidationEventHandler h, XmlSchema schema)
 {
     if (this.CompilationId == schema.CompilationId)
     {
         return(0);
     }
     if (this.isRedefinedComponent)
     {
         if (base.Annotation != null)
         {
             base.Annotation.isRedefinedComponent = true;
         }
         if (this.AnyAttribute != null)
         {
             this.AnyAttribute.isRedefinedComponent = true;
         }
         foreach (XmlSchemaObject xmlSchemaObject in this.Attributes)
         {
             xmlSchemaObject.isRedefinedComponent = true;
         }
         if (this.Particle != null)
         {
             this.Particle.isRedefinedComponent = true;
         }
     }
     if (this.BaseTypeName == null || this.BaseTypeName.IsEmpty)
     {
         base.error(h, "base must be present, as a QName");
     }
     else if (!XmlSchemaUtil.CheckQName(this.BaseTypeName))
     {
         base.error(h, "BaseTypeName is not a valid XmlQualifiedName");
     }
     if (this.AnyAttribute != null)
     {
         this.errorCount += this.AnyAttribute.Compile(h, schema);
     }
     foreach (XmlSchemaObject xmlSchemaObject2 in this.Attributes)
     {
         if (xmlSchemaObject2 is XmlSchemaAttribute)
         {
             XmlSchemaAttribute xmlSchemaAttribute = (XmlSchemaAttribute)xmlSchemaObject2;
             this.errorCount += xmlSchemaAttribute.Compile(h, schema);
         }
         else if (xmlSchemaObject2 is XmlSchemaAttributeGroupRef)
         {
             XmlSchemaAttributeGroupRef xmlSchemaAttributeGroupRef = (XmlSchemaAttributeGroupRef)xmlSchemaObject2;
             this.errorCount += xmlSchemaAttributeGroupRef.Compile(h, schema);
         }
         else
         {
             base.error(h, xmlSchemaObject2.GetType() + " is not valid in this place::ComplexConetnetExtension");
         }
     }
     if (this.Particle != null)
     {
         if (this.Particle is XmlSchemaGroupRef)
         {
             this.errorCount += ((XmlSchemaGroupRef)this.Particle).Compile(h, schema);
         }
         else if (this.Particle is XmlSchemaAll)
         {
             this.errorCount += ((XmlSchemaAll)this.Particle).Compile(h, schema);
         }
         else if (this.Particle is XmlSchemaChoice)
         {
             this.errorCount += ((XmlSchemaChoice)this.Particle).Compile(h, schema);
         }
         else if (this.Particle is XmlSchemaSequence)
         {
             this.errorCount += ((XmlSchemaSequence)this.Particle).Compile(h, schema);
         }
         else
         {
             base.error(h, "Particle of a restriction is limited only to group, sequence, choice and all.");
         }
     }
     XmlSchemaUtil.CompileID(base.Id, this, schema.IDCollection, h);
     this.CompilationId = schema.CompilationId;
     return(this.errorCount);
 }
        ///<remarks>
        /// 1. Base must be present and a QName
        ///</remarks>
        internal override int Compile(ValidationEventHandler h, XmlSchema schema)
        {
            // If this is already compiled this time, simply skip.
            if (CompilationId == schema.CompilationId)
            {
                return(0);
            }

            if (this.isRedefinedComponent)
            {
                if (Annotation != null)
                {
                    Annotation.isRedefinedComponent = true;
                }
                if (AnyAttribute != null)
                {
                    AnyAttribute.isRedefinedComponent = true;
                }
                foreach (XmlSchemaObject obj in Attributes)
                {
                    obj.isRedefinedComponent = true;
                }
            }

            if (BaseTypeName == null || BaseTypeName.IsEmpty)
            {
                error(h, "base must be present, as a QName");
            }
            else if (!XmlSchemaUtil.CheckQName(BaseTypeName))
            {
                error(h, "BaseTypeName must be a QName");
            }

            if (this.AnyAttribute != null)
            {
                errorCount += AnyAttribute.Compile(h, schema);
            }

            foreach (XmlSchemaObject obj in Attributes)
            {
                if (obj is XmlSchemaAttribute)
                {
                    XmlSchemaAttribute attr = (XmlSchemaAttribute)obj;
                    errorCount += attr.Compile(h, schema);
                }
                else if (obj is XmlSchemaAttributeGroupRef)
                {
                    XmlSchemaAttributeGroupRef atgrp = (XmlSchemaAttributeGroupRef)obj;
                    errorCount += atgrp.Compile(h, schema);
                }
                else
                {
                    error(h, obj.GetType() + " is not valid in this place::SimpleConentExtension");
                }
            }

            XmlSchemaUtil.CompileID(Id, this, schema.IDCollection, h);

            this.CompilationId = schema.CompilationId;
            return(errorCount);
        }
Beispiel #7
0
        void DoCompile(ValidationEventHandler handler, List <CompiledSchemaMemo> handledUris, XmlSchemaSet col, XmlResolver resolver)
        {
            SetParent();
            CompilationId = col.CompilationId;
            schemas       = col;
            if (!schemas.Contains(this))              // e.g. xs:import
            {
                schemas.Add(this);
            }

            attributeGroups.Clear();
            attributes.Clear();
            elements.Clear();
            groups.Clear();
            notations.Clear();
            schemaTypes.Clear();
            named_identities.Clear();
            ids.Clear();
            compilationItems.Clear();

            //1. Union and List are not allowed in block default
            if (BlockDefault != XmlSchemaDerivationMethod.All)
            {
                if ((BlockDefault & XmlSchemaDerivationMethod.List) != 0)
                {
                    error(handler, "list is not allowed in blockDefault attribute");
                }
                if ((BlockDefault & XmlSchemaDerivationMethod.Union) != 0)
                {
                    error(handler, "union is not allowed in blockDefault attribute");
                }
            }

            //2. Substitution is not allowed in finaldefault.
            if (FinalDefault != XmlSchemaDerivationMethod.All)
            {
                if ((FinalDefault & XmlSchemaDerivationMethod.Substitution) != 0)
                {
                    error(handler, "substitution is not allowed in finalDefault attribute");
                }
            }

            //3. id must be of type ID
            XmlSchemaUtil.CompileID(Id, this, IDCollection, handler);

            //4. targetNamespace should be of type anyURI or absent
            if (TargetNamespace != null)
            {
                if (TargetNamespace.Length == 0)
                {
                    error(handler, "The targetNamespace attribute cannot have have empty string as its value.");
                }

                if (!XmlSchemaUtil.CheckAnyUri(TargetNamespace))
                {
                    error(handler, TargetNamespace + " is not a valid value for targetNamespace attribute of schema");
                }
            }

            //5. version should be of type normalizedString
            if (!XmlSchemaUtil.CheckNormalizedString(Version))
            {
                error(handler, Version + "is not a valid value for version attribute of schema");
            }

            // Compile the content of this schema

            for (int i = 0; i < Items.Count; i++)
            {
                compilationItems.Add(Items [i]);
            }

            // First, we run into inclusion schemas to collect
            // compilation target items into compiledItems.
            for (int i = 0; i < Includes.Count; i++)
            {
                ProcessExternal(handler, handledUris, resolver, Includes [i] as XmlSchemaExternal, col);
            }

            // Compilation phase.
            // At least each Compile() must give unique (qualified) name for each component.
            // It also checks self-resolvable properties correctness.
            // Post compilation schema information contribution is not done here.
            // It should be done by Validate().
            for (int i = 0; i < compilationItems.Count; i++)
            {
                XmlSchemaObject obj = compilationItems [i];
                if (obj is XmlSchemaAnnotation)
                {
                    int numerr = ((XmlSchemaAnnotation)obj).Compile(handler, this);
                    errorCount += numerr;
                }
                else if (obj is XmlSchemaAttribute)
                {
                    XmlSchemaAttribute attr = (XmlSchemaAttribute)obj;
                    int numerr = attr.Compile(handler, this);
                    errorCount += numerr;
                    if (numerr == 0)
                    {
                        XmlSchemaUtil.AddToTable(Attributes, attr, attr.QualifiedName, handler);
                    }
                }
                else if (obj is XmlSchemaAttributeGroup)
                {
                    XmlSchemaAttributeGroup attrgrp = (XmlSchemaAttributeGroup)obj;
                    int numerr = attrgrp.Compile(handler, this);
                    errorCount += numerr;
                    if (numerr == 0)
                    {
                        XmlSchemaUtil.AddToTable(
                            AttributeGroups,
                            attrgrp,
                            attrgrp.QualifiedName,
                            handler);
                    }
                }
                else if (obj is XmlSchemaComplexType)
                {
                    XmlSchemaComplexType ctype = (XmlSchemaComplexType)obj;
                    int numerr = ctype.Compile(handler, this);
                    errorCount += numerr;
                    if (numerr == 0)
                    {
                        XmlSchemaUtil.AddToTable(
                            schemaTypes,
                            ctype,
                            ctype.QualifiedName,
                            handler);
                    }
                }
                else if (obj is XmlSchemaSimpleType)
                {
                    XmlSchemaSimpleType stype = (XmlSchemaSimpleType)obj;
                    stype.islocal = false;                     //This simple type is toplevel
                    int numerr = stype.Compile(handler, this);
                    errorCount += numerr;
                    if (numerr == 0)
                    {
                        XmlSchemaUtil.AddToTable(
                            SchemaTypes,
                            stype,
                            stype.QualifiedName,
                            handler);
                    }
                }
                else if (obj is XmlSchemaElement)
                {
                    XmlSchemaElement elem = (XmlSchemaElement)obj;
                    elem.parentIsSchema = true;
                    int numerr = elem.Compile(handler, this);
                    errorCount += numerr;
                    if (numerr == 0)
                    {
                        XmlSchemaUtil.AddToTable(
                            Elements,
                            elem,
                            elem.QualifiedName,
                            handler);
                    }
                }
                else if (obj is XmlSchemaGroup)
                {
                    XmlSchemaGroup grp    = (XmlSchemaGroup)obj;
                    int            numerr = grp.Compile(handler, this);
                    errorCount += numerr;
                    if (numerr == 0)
                    {
                        XmlSchemaUtil.AddToTable(
                            Groups,
                            grp,
                            grp.QualifiedName,
                            handler);
                    }
                }
                else if (obj is XmlSchemaNotation)
                {
                    XmlSchemaNotation ntn = (XmlSchemaNotation)obj;
                    int numerr            = ntn.Compile(handler, this);
                    errorCount += numerr;
                    if (numerr == 0)
                    {
                        XmlSchemaUtil.AddToTable(
                            Notations,
                            ntn,
                            ntn.QualifiedName,
                            handler);
                    }
                }
                else
                {
                    ValidationHandler.RaiseValidationEvent(
                        handler,
                        null,
                        String.Format("Object of Type {0} is not valid in Item Property of Schema", obj.GetType().Name),
                        null,
                        this,
                        null,
                        XmlSeverityType.Error);
                }
            }
        }
Beispiel #8
0
        void DoCompile(ValidationEventHandler handler, Hashtable handledUris, XmlSchemaSet col, XmlResolver resolver)
        {
            SetParent();
            CompilationId = col.CompilationId;
            schemas       = col;
            if (!schemas.Contains(this))              // e.g. xs:import
            {
                schemas.Add(this);
            }

            attributeGroups.Clear();
            attributes.Clear();
            elements.Clear();
            groups.Clear();
            notations.Clear();
            schemaTypes.Clear();

            //1. Union and List are not allowed in block default
            if (BlockDefault != XmlSchemaDerivationMethod.All)
            {
                if ((BlockDefault & XmlSchemaDerivationMethod.List) != 0)
                {
                    error(handler, "list is not allowed in blockDefault attribute");
                }
                if ((BlockDefault & XmlSchemaDerivationMethod.Union) != 0)
                {
                    error(handler, "union is not allowed in blockDefault attribute");
                }
            }

            //2. Substitution is not allowed in finaldefault.
            if (FinalDefault != XmlSchemaDerivationMethod.All)
            {
                if ((FinalDefault & XmlSchemaDerivationMethod.Substitution) != 0)
                {
                    error(handler, "substitution is not allowed in finalDefault attribute");
                }
            }

            //3. id must be of type ID
            XmlSchemaUtil.CompileID(Id, this, col.IDCollection, handler);

            //4. targetNamespace should be of type anyURI or absent
            if (TargetNamespace != null)
            {
                if (TargetNamespace.Length == 0)
                {
                    error(handler, "The targetNamespace attribute cannot have have empty string as its value.");
                }

                if (!XmlSchemaUtil.CheckAnyUri(TargetNamespace))
                {
                    error(handler, TargetNamespace + " is not a valid value for targetNamespace attribute of schema");
                }
            }

            //5. version should be of type normalizedString
            if (!XmlSchemaUtil.CheckNormalizedString(Version))
            {
                error(handler, Version + "is not a valid value for version attribute of schema");
            }

            // Compile the content of this schema

            compilationItems = new XmlSchemaObjectCollection();
            for (int i = 0; i < Items.Count; i++)
            {
                compilationItems.Add(Items [i]);
            }

            // First, we run into inclusion schemas to collect
            // compilation target items into compiledItems.
            for (int i = 0; i < Includes.Count; i++)
            {
                XmlSchemaExternal ext = Includes [i] as XmlSchemaExternal;
                if (ext == null)
                {
                    error(handler, String.Format("Object of Type {0} is not valid in Includes Property of XmlSchema", Includes [i].GetType().Name));
                    continue;
                }

                if (ext.SchemaLocation == null)
                {
                    continue;
                }

                Stream stream = null;
                string url    = null;
                if (resolver != null)
                {
                    url = GetResolvedUri(resolver, ext.SchemaLocation);
                    if (handledUris.Contains(url))
                    {
                        // This schema is already handled, so simply skip (otherwise, duplicate definition errrors occur.
                        continue;
                    }
                    handledUris.Add(url, url);
                    try {
                        stream = resolver.GetEntity(new Uri(url), null, typeof(Stream)) as Stream;
                    } catch (Exception) {
                        // LAMESPEC: This is not good way to handle errors, but since we cannot know what kind of XmlResolver will come, so there are no mean to avoid this ugly catch.
                        warn(handler, "Could not resolve schema location URI: " + url);
                        stream = null;
                    }
                }

                // Process redefinition children in advance.
                XmlSchemaRedefine redefine = Includes [i] as XmlSchemaRedefine;
                if (redefine != null)
                {
                    for (int j = 0; j < redefine.Items.Count; j++)
                    {
                        XmlSchemaObject redefinedObj = redefine.Items [j];
                        redefinedObj.isRedefinedComponent = true;
                        redefinedObj.isRedefineChild      = true;
                        if (redefinedObj is XmlSchemaType ||
                            redefinedObj is XmlSchemaGroup ||
                            redefinedObj is XmlSchemaAttributeGroup)
                        {
                            compilationItems.Add(redefinedObj);
                        }
                        else
                        {
                            error(handler, "Redefinition is only allowed to simpleType, complexType, group and attributeGroup.");
                        }
                    }
                }

                XmlSchema includedSchema = null;
                if (stream == null)
                {
                    // It is missing schema components.
                    missedSubComponents = true;
                    continue;
                }
                else
                {
                    XmlTextReader xtr = null;
                    try {
                        xtr            = new XmlTextReader(url, stream, nameTable);
                        includedSchema = XmlSchema.Read(xtr, handler);
                    } finally {
                        if (xtr != null)
                        {
                            xtr.Close();
                        }
                    }
                    includedSchema.schemas = schemas;
                }
                includedSchema.SetParent();
                ext.Schema = includedSchema;

                // Set - actual - target namespace for the included schema * before compilation*.
                XmlSchemaImport import = ext as XmlSchemaImport;
                if (import != null)
                {
                    if (TargetNamespace == includedSchema.TargetNamespace)
                    {
                        error(handler, "Target namespace must be different from that of included schema.");
                        continue;
                    }
                    else if (includedSchema.TargetNamespace != import.Namespace)
                    {
                        error(handler, "Attribute namespace and its importing schema's target namespace must be the same.");
                        continue;
                    }
                }
                else
                {
                    if (TargetNamespace == null &&
                        includedSchema.TargetNamespace != null)
                    {
                        error(handler, "Target namespace is required to include a schema which has its own target namespace");
                        continue;
                    }
                    else if (TargetNamespace != null &&
                             includedSchema.TargetNamespace == null)
                    {
                        includedSchema.TargetNamespace = TargetNamespace;
                    }
                }

                // Do not compile included schema here.

                AddExternalComponentsTo(includedSchema, compilationItems);
            }

            // Compilation phase.
            // At least each Compile() must give unique (qualified) name for each component.
            // It also checks self-resolvable properties correctness.
            // Post compilation schema information contribution is not done here.
            // It should be done by Validate().
            for (int i = 0; i < compilationItems.Count; i++)
            {
                XmlSchemaObject obj = compilationItems [i];
                if (obj is XmlSchemaAnnotation)
                {
                    int numerr = ((XmlSchemaAnnotation)obj).Compile(handler, this);
                    errorCount += numerr;
                }
                else if (obj is XmlSchemaAttribute)
                {
                    XmlSchemaAttribute attr = (XmlSchemaAttribute)obj;
                    int numerr = attr.Compile(handler, this);
                    errorCount += numerr;
                    if (numerr == 0)
                    {
                        XmlSchemaUtil.AddToTable(Attributes, attr, attr.QualifiedName, handler);
                    }
                }
                else if (obj is XmlSchemaAttributeGroup)
                {
                    XmlSchemaAttributeGroup attrgrp = (XmlSchemaAttributeGroup)obj;
                    int numerr = attrgrp.Compile(handler, this);
                    errorCount += numerr;
                    if (numerr == 0)
                    {
                        XmlSchemaUtil.AddToTable(
                            AttributeGroups,
                            attrgrp,
                            attrgrp.QualifiedName,
                            handler);
                    }
                }
                else if (obj is XmlSchemaComplexType)
                {
                    XmlSchemaComplexType ctype = (XmlSchemaComplexType)obj;
                    int numerr = ctype.Compile(handler, this);
                    errorCount += numerr;
                    if (numerr == 0)
                    {
                        XmlSchemaUtil.AddToTable(
                            schemaTypes,
                            ctype,
                            ctype.QualifiedName,
                            handler);
                    }
                }
                else if (obj is XmlSchemaSimpleType)
                {
                    XmlSchemaSimpleType stype = (XmlSchemaSimpleType)obj;
                    stype.islocal = false;                     //This simple type is toplevel
                    int numerr = stype.Compile(handler, this);
                    errorCount += numerr;
                    if (numerr == 0)
                    {
                        XmlSchemaUtil.AddToTable(
                            SchemaTypes,
                            stype,
                            stype.QualifiedName,
                            handler);
                    }
                }
                else if (obj is XmlSchemaElement)
                {
                    XmlSchemaElement elem = (XmlSchemaElement)obj;
                    elem.parentIsSchema = true;
                    int numerr = elem.Compile(handler, this);
                    errorCount += numerr;
                    if (numerr == 0)
                    {
                        XmlSchemaUtil.AddToTable(
                            Elements,
                            elem,
                            elem.QualifiedName,
                            handler);
                    }
                }
                else if (obj is XmlSchemaGroup)
                {
                    XmlSchemaGroup grp    = (XmlSchemaGroup)obj;
                    int            numerr = grp.Compile(handler, this);
                    errorCount += numerr;
                    if (numerr == 0)
                    {
                        XmlSchemaUtil.AddToTable(
                            Groups,
                            grp,
                            grp.QualifiedName,
                            handler);
                    }
                }
                else if (obj is XmlSchemaNotation)
                {
                    XmlSchemaNotation ntn = (XmlSchemaNotation)obj;
                    int numerr            = ntn.Compile(handler, this);
                    errorCount += numerr;
                    if (numerr == 0)
                    {
                        XmlSchemaUtil.AddToTable(
                            Notations,
                            ntn,
                            ntn.QualifiedName,
                            handler);
                    }
                }
                else
                {
                    ValidationHandler.RaiseValidationEvent(
                        handler,
                        null,
                        String.Format("Object of Type {0} is not valid in Item Property of Schema", obj.GetType().Name),
                        null,
                        this,
                        null,
                        XmlSeverityType.Error);
                }
            }
        }