private ContentValidator CompileComplexContent(XmlSchemaComplexType complexType)
 {
     if (complexType.ContentType == XmlSchemaContentType.Empty)
     {
         return ContentValidator.Empty;
     }
     if (complexType.ContentType == XmlSchemaContentType.TextOnly)
     {
         return ContentValidator.TextOnly;
     }
     XmlSchemaParticle contentTypeParticle = complexType.ContentTypeParticle;
     if ((contentTypeParticle == null) || (contentTypeParticle == XmlSchemaParticle.Empty))
     {
         if (complexType.ContentType == XmlSchemaContentType.ElementOnly)
         {
             return ContentValidator.Empty;
         }
         return ContentValidator.Mixed;
     }
     this.PushComplexType(complexType);
     if (contentTypeParticle is XmlSchemaAll)
     {
         XmlSchemaAll all = (XmlSchemaAll) contentTypeParticle;
         AllElementsContentValidator validator = new AllElementsContentValidator(complexType.ContentType, all.Items.Count, all.MinOccurs == 0M);
         for (int i = 0; i < all.Items.Count; i++)
         {
             XmlSchemaElement particle = (XmlSchemaElement) all.Items[i];
             if (!validator.AddElement(particle.QualifiedName, particle, particle.MinOccurs == 0M))
             {
                 base.SendValidationEvent("Sch_DupElement", particle.QualifiedName.ToString(), particle);
             }
         }
         return validator;
     }
     ParticleContentValidator contentValidator = new ParticleContentValidator(complexType.ContentType);
     try
     {
         contentValidator.Start();
         this.BuildParticleContentModel(contentValidator, contentTypeParticle);
         return contentValidator.Finish(this.compileContentModel);
     }
     catch (UpaException exception)
     {
         if (exception.Particle1 is XmlSchemaElement)
         {
             if (exception.Particle2 is XmlSchemaElement)
             {
                 base.SendValidationEvent("Sch_NonDeterministic", ((XmlSchemaElement) exception.Particle1).QualifiedName.ToString(), (XmlSchemaElement) exception.Particle2);
             }
             else
             {
                 base.SendValidationEvent("Sch_NonDeterministicAnyEx", ((XmlSchemaAny) exception.Particle2).NamespaceList.ToString(), ((XmlSchemaElement) exception.Particle1).QualifiedName.ToString(), (XmlSchemaAny) exception.Particle2);
             }
         }
         else if (exception.Particle2 is XmlSchemaElement)
         {
             base.SendValidationEvent("Sch_NonDeterministicAnyEx", ((XmlSchemaAny) exception.Particle1).NamespaceList.ToString(), ((XmlSchemaElement) exception.Particle2).QualifiedName.ToString(), (XmlSchemaAny) exception.Particle1);
         }
         else
         {
             base.SendValidationEvent("Sch_NonDeterministicAnyAny", ((XmlSchemaAny) exception.Particle1).NamespaceList.ToString(), ((XmlSchemaAny) exception.Particle2).NamespaceList.ToString(), (XmlSchemaAny) exception.Particle1);
         }
         return XmlSchemaComplexType.AnyTypeContentValidator;
     }
     catch (NotSupportedException)
     {
         base.SendValidationEvent("Sch_ComplexContentModel", complexType, XmlSeverityType.Warning);
         return XmlSchemaComplexType.AnyTypeContentValidator;
     }
 }
        private ContentValidator CompileComplexContent(XmlSchemaComplexType complexType) {
            if (complexType.ContentType == XmlSchemaContentType.Empty) {
                return ContentValidator.Empty;
            }
            else if (complexType.ContentType == XmlSchemaContentType.TextOnly) {
                return ContentValidator.TextOnly;
            }
            XmlSchemaParticle particle = complexType.ContentTypeParticle;
            if (particle == null || particle == XmlSchemaParticle.Empty) {
                if (complexType.ContentType == XmlSchemaContentType.ElementOnly) {
                    return ContentValidator.Empty;
                }
                else {
                    return ContentValidator.Mixed;
                }
            }
            PushComplexType(complexType);
            if (particle is XmlSchemaAll) {
                XmlSchemaAll all = (XmlSchemaAll)particle;
                AllElementsContentValidator contentValidator = new AllElementsContentValidator(complexType.ContentType, all.Items.Count, all.MinOccurs == decimal.Zero);
                for (int i = 0; i < all.Items.Count; ++i) {
                    XmlSchemaElement localElement = (XmlSchemaElement)all.Items[i];
                    if (!contentValidator.AddElement(localElement.QualifiedName, localElement, localElement.MinOccurs == decimal.Zero)) {
                       SendValidationEvent(Res.Sch_DupElement, localElement.QualifiedName.ToString(), localElement);
                    }
                }
                return contentValidator;
            }
            else {
                ParticleContentValidator contentValidator = new ParticleContentValidator(complexType.ContentType, CompilationSettings.EnableUpaCheck);
#if DEBUG
                string name = complexType.Name != null ? complexType.Name : string.Empty;
                Debug.WriteLineIf(DiagnosticsSwitches.XmlSchema.TraceVerbose, "CompileComplexContent: "+ name  + DumpContentModel(particle));
#endif
                try {
                    contentValidator.Start();
                    complexType.HasWildCard = BuildParticleContentModel(contentValidator, particle);
                    return contentValidator.Finish(true);                         
                }
                catch(UpaException e) {
                    if (e.Particle1 is XmlSchemaElement) {
                        if (e.Particle2 is XmlSchemaElement) {
                            SendValidationEvent(Res.Sch_NonDeterministic, ((XmlSchemaElement)e.Particle1).QualifiedName.ToString(), (XmlSchemaElement)e.Particle2);
                        }
                        else {
                            SendValidationEvent(Res.Sch_NonDeterministicAnyEx, ((XmlSchemaAny)e.Particle2).ResolvedNamespace, ((XmlSchemaElement)e.Particle1).QualifiedName.ToString(), (XmlSchemaAny)e.Particle2);
                        }
                    }
                    else {
                        if (e.Particle2 is XmlSchemaElement) {
                            SendValidationEvent(Res.Sch_NonDeterministicAnyEx, ((XmlSchemaAny)e.Particle1).ResolvedNamespace, ((XmlSchemaElement)e.Particle2).QualifiedName.ToString(), (XmlSchemaElement)e.Particle2);
                        }
                        else {
                            SendValidationEvent(Res.Sch_NonDeterministicAnyAny, ((XmlSchemaAny)e.Particle1).ResolvedNamespace, ((XmlSchemaAny)e.Particle2).ResolvedNamespace, (XmlSchemaAny)e.Particle2);
                        }
                    }
                    return XmlSchemaComplexType.AnyTypeContentValidator;
                }
                catch(NotSupportedException) {
                    SendValidationEvent(Res.Sch_ComplexContentModel, complexType, XmlSeverityType.Warning);
                    return XmlSchemaComplexType.AnyTypeContentValidator;
                }
            }
        }