private static XmlSchemaComplexType CreateAnyType(XmlSchemaContentProcessing processContents)
 {
     XmlSchemaComplexType type = new XmlSchemaComplexType();
     type.SetQualifiedName(DatatypeImplementation.QnAnyType);
     XmlSchemaAny item = new XmlSchemaAny {
         MinOccurs = 0M,
         MaxOccurs = 79228162514264337593543950335M,
         ProcessContents = processContents
     };
     item.BuildNamespaceList(null);
     XmlSchemaSequence sequence = new XmlSchemaSequence();
     sequence.Items.Add(item);
     type.SetContentTypeParticle(sequence);
     type.SetContentType(XmlSchemaContentType.Mixed);
     type.ElementDecl = SchemaElementDecl.CreateAnyTypeElementDecl();
     type.ElementDecl.SchemaType = type;
     ParticleContentValidator validator = new ParticleContentValidator(XmlSchemaContentType.Mixed);
     validator.Start();
     validator.OpenGroup();
     validator.AddNamespaceList(item.NamespaceList, item);
     validator.AddStar();
     validator.CloseGroup();
     ContentValidator validator2 = validator.Finish(true);
     type.ElementDecl.ContentValidator = validator2;
     XmlSchemaAnyAttribute attribute = new XmlSchemaAnyAttribute {
         ProcessContents = processContents
     };
     attribute.BuildNamespaceList(null);
     type.SetAttributeWildcard(attribute);
     type.ElementDecl.AnyAttribute = attribute;
     return type;
 }
 private bool BuildParticleContentModel(ParticleContentValidator contentValidator, XmlSchemaParticle particle)
 {
     bool flag = false;
     if (particle is XmlSchemaElement)
     {
         XmlSchemaElement element = (XmlSchemaElement) particle;
         contentValidator.AddName(element.QualifiedName, element);
     }
     else if (particle is XmlSchemaAny)
     {
         flag = true;
         XmlSchemaAny any = (XmlSchemaAny) particle;
         contentValidator.AddNamespaceList(any.NamespaceList, any);
     }
     else if (particle is XmlSchemaGroupBase)
     {
         XmlSchemaObjectCollection items = ((XmlSchemaGroupBase) particle).Items;
         bool flag2 = particle is XmlSchemaChoice;
         contentValidator.OpenGroup();
         bool flag3 = true;
         for (int i = 0; i < items.Count; i++)
         {
             if (flag3)
             {
                 flag3 = false;
             }
             else if (flag2)
             {
                 contentValidator.AddChoice();
             }
             else
             {
                 contentValidator.AddSequence();
             }
             flag = this.BuildParticleContentModel(contentValidator, (XmlSchemaParticle) items[i]);
         }
         contentValidator.CloseGroup();
     }
     if ((particle.MinOccurs != 1M) || (particle.MaxOccurs != 1M))
     {
         if ((particle.MinOccurs == 0M) && (particle.MaxOccurs == 1M))
         {
             contentValidator.AddQMark();
             return flag;
         }
         if ((particle.MinOccurs == 0M) && (particle.MaxOccurs == 79228162514264337593543950335M))
         {
             contentValidator.AddStar();
             return flag;
         }
         if ((particle.MinOccurs == 1M) && (particle.MaxOccurs == 79228162514264337593543950335M))
         {
             contentValidator.AddPlus();
             return flag;
         }
         contentValidator.AddLeafRange(particle.MinOccurs, particle.MaxOccurs);
     }
     return flag;
 }
Beispiel #3
0
        private static XmlSchemaComplexType CreateAnyType(XmlSchemaContentProcessing processContents)
        {
            XmlSchemaComplexType localAnyType = new XmlSchemaComplexType();

            localAnyType.SetQualifiedName(DatatypeImplementation.QnAnyType);

            XmlSchemaAny anyElement = new XmlSchemaAny();

            anyElement.MinOccurs = decimal.Zero;
            anyElement.MaxOccurs = decimal.MaxValue;

            anyElement.ProcessContents = processContents;
            anyElement.BuildNamespaceList(null);
            XmlSchemaSequence seq = new XmlSchemaSequence();

            seq.Items.Add(anyElement);

            localAnyType.SetContentTypeParticle(seq);
            localAnyType.SetContentType(XmlSchemaContentType.Mixed);

            localAnyType.ElementDecl            = SchemaElementDecl.CreateAnyTypeElementDecl();
            localAnyType.ElementDecl.SchemaType = localAnyType;

            //Create contentValidator for Any
            ParticleContentValidator contentValidator = new ParticleContentValidator(XmlSchemaContentType.Mixed);

            contentValidator.Start();
            contentValidator.OpenGroup();
            contentValidator.AddNamespaceList(anyElement.NamespaceList !, anyElement);
            contentValidator.AddStar();
            contentValidator.CloseGroup();
            ContentValidator anyContentValidator = contentValidator.Finish(true);

            localAnyType.ElementDecl.ContentValidator = anyContentValidator;

            XmlSchemaAnyAttribute anyAttribute = new XmlSchemaAnyAttribute();

            anyAttribute.ProcessContents = processContents;
            anyAttribute.BuildNamespaceList(null);
            localAnyType.SetAttributeWildcard(anyAttribute);
            localAnyType.ElementDecl.AnyAttribute = anyAttribute;
            return(localAnyType);
        }
        private static XmlSchemaComplexType CreateAnyType(XmlSchemaContentProcessing processContents)
        {
            XmlSchemaComplexType localAnyType = new XmlSchemaComplexType();
            localAnyType.SetQualifiedName(DatatypeImplementation.QnAnyType);

            XmlSchemaAny anyElement = new XmlSchemaAny();
            anyElement.MinOccurs = decimal.Zero;
            anyElement.MaxOccurs = decimal.MaxValue;

            anyElement.ProcessContents = processContents;
            anyElement.BuildNamespaceList(null);
            XmlSchemaSequence seq = new XmlSchemaSequence();
            seq.Items.Add(anyElement);

            localAnyType.SetContentTypeParticle(seq);
            localAnyType.SetContentType(XmlSchemaContentType.Mixed);

            localAnyType.ElementDecl = SchemaElementDecl.CreateAnyTypeElementDecl();
            localAnyType.ElementDecl.SchemaType = localAnyType;

            //Create contentValidator for Any
            ParticleContentValidator contentValidator = new ParticleContentValidator(XmlSchemaContentType.Mixed);
            contentValidator.Start();
            contentValidator.OpenGroup();
            contentValidator.AddNamespaceList(anyElement.NamespaceList, anyElement);
            contentValidator.AddStar();
            contentValidator.CloseGroup();
            ContentValidator anyContentValidator = contentValidator.Finish(true);
            localAnyType.ElementDecl.ContentValidator = anyContentValidator;

            XmlSchemaAnyAttribute anyAttribute = new XmlSchemaAnyAttribute();
            anyAttribute.ProcessContents = processContents;
            anyAttribute.BuildNamespaceList(null);
            localAnyType.SetAttributeWildcard(anyAttribute);
            localAnyType.ElementDecl.AnyAttribute = anyAttribute;
            return localAnyType;
        }
Beispiel #5
0
        private void ParseElementMixedContent(ParticleContentValidator pcv, int startParenEntityId)
        {
            bool hasNames = false;
            int connectorEntityId = -1;
            int contentEntityId = _currentEntityId;

            for (;;)
            {
                switch (GetToken(false))
                {
                    case Token.RightParen:
                        pcv.CloseGroup();
                        if (_validate && _currentEntityId != startParenEntityId)
                        {
                            SendValidationEvent(_curPos, XmlSeverityType.Error, SR.Sch_ParEntityRefNesting, string.Empty);
                        }
                        if (GetToken(false) == Token.Star && hasNames)
                        {
                            pcv.AddStar();
                        }
                        else if (hasNames)
                        {
                            ThrowUnexpectedToken(_curPos, "*");
                        }
                        return;
                    case Token.Or:
                        if (!hasNames)
                        {
                            hasNames = true;
                        }
                        else
                        {
                            pcv.AddChoice();
                        }
                        if (_validate)
                        {
                            connectorEntityId = _currentEntityId;
                            if (contentEntityId < connectorEntityId)
                            {  // entity repl.text starting with connector
                                SendValidationEvent(_curPos, XmlSeverityType.Error, SR.Sch_ParEntityRefNesting, string.Empty);
                            }
                        }

                        if (GetToken(false) != Token.QName)
                        {
                            goto default;
                        }

                        XmlQualifiedName name = GetNameQualified(true);
                        if (pcv.Exists(name) && _validate)
                        {
                            SendValidationEvent(XmlSeverityType.Error, SR.Sch_DupElement, name.ToString());
                        }
                        pcv.AddName(name, null);

                        if (_validate)
                        {
                            contentEntityId = _currentEntityId;
                            if (contentEntityId < connectorEntityId)
                            { // entity repl.text ending with connector
                                SendValidationEvent(_curPos, XmlSeverityType.Error, SR.Sch_ParEntityRefNesting, string.Empty);
                            }
                        }
                        continue;
                    default:
                        OnUnexpectedError();
                        break;
                }
            }
        }
Beispiel #6
0
 private void ParseHowMany(ParticleContentValidator pcv)
 {
     switch (GetToken(false))
     {
         case Token.Star:
             pcv.AddStar();
             return;
         case Token.QMark:
             pcv.AddQMark();
             return;
         case Token.Plus:
             pcv.AddPlus();
             return;
         default:
             return;
     }
 }
Beispiel #7
0
        private void ParseElementOnlyContent(ParticleContentValidator pcv, int startParenEntityId)
        {
            Stack<ParseElementOnlyContent_LocalFrame> localFrames = new Stack<ParseElementOnlyContent_LocalFrame>();
            ParseElementOnlyContent_LocalFrame currentFrame = new ParseElementOnlyContent_LocalFrame(startParenEntityId);
            localFrames.Push(currentFrame);

        RecursiveCall:

        Loop:
            switch (GetToken(false))
            {
                case Token.QName:
                    pcv.AddName(GetNameQualified(true), null);
                    ParseHowMany(pcv);
                    break;
                case Token.LeftParen:
                    pcv.OpenGroup();

                    // We could just do this:
                    // ParseElementOnlyContent( pcv, currentEntityId );
                    // 
                    // But that would be recursion - so we will simulate the call using our localFrames stack 
                    //   instead. 
                    currentFrame =
                        new ParseElementOnlyContent_LocalFrame(_currentEntityId);
                    localFrames.Push(currentFrame);
                    goto RecursiveCall;
                // And we should return here when we return from recursion call 
                //   but it's the same as returning after the switch statement 

                case Token.GreaterThan:
                    Throw(_curPos, SR.Xml_InvalidContentModel);
                    goto Return;
                default:
                    goto UnexpectedError;
            }

        ReturnFromRecursiveCall:
            switch (GetToken(false))
            {
                case Token.Comma:
                    if (currentFrame.parsingSchema == Token.Or)
                    {
                        Throw(_curPos, SR.Xml_InvalidContentModel);
                    }
                    pcv.AddSequence();
                    currentFrame.parsingSchema = Token.Comma;
                    break;
                case Token.Or:
                    if (currentFrame.parsingSchema == Token.Comma)
                    {
                        Throw(_curPos, SR.Xml_InvalidContentModel);
                    }
                    pcv.AddChoice();
                    currentFrame.parsingSchema = Token.Or;
                    break;
                case Token.RightParen:
                    pcv.CloseGroup();
                    if (_validate && _currentEntityId != currentFrame.startParenEntityId)
                    {
                        SendValidationEvent(_curPos, XmlSeverityType.Error, SR.Sch_ParEntityRefNesting, string.Empty);
                    }
                    ParseHowMany(pcv);
                    goto Return;
                case Token.GreaterThan:
                    Throw(_curPos, SR.Xml_InvalidContentModel);
                    goto Return;
                default:
                    goto UnexpectedError;
            }
            goto Loop;

        UnexpectedError:
            OnUnexpectedError();

        Return:
            // This is equivalent to return; statement
            //   we simlate it using our localFrames stack
            localFrames.Pop();
            if (localFrames.Count > 0)
            {
                currentFrame = (ParseElementOnlyContent_LocalFrame)localFrames.Peek();
                goto ReturnFromRecursiveCall;
            }
            else
            {
                return;
            }
        }
Beispiel #8
0
 private static void HandleMinMax(ParticleContentValidator pContent, uint cMin, uint cMax)
 {
     if (pContent != null)
     {
         if (cMax == uint.MaxValue)
         {
             if (cMin == 0)
                 pContent.AddStar();           // minOccurs="0" and maxOccurs="infinite"
             else
                 pContent.AddPlus();           // minOccurs="1" and maxOccurs="infinite"
         }
         else if (cMin == 0)
         {                 // minOccurs="0" and maxOccurs="1")
             pContent.AddQMark();
         }
     }
 }
 private bool BuildParticleContentModel(ParticleContentValidator contentValidator, XmlSchemaParticle particle) {
     bool hasWildCard = false;
     if (particle is XmlSchemaElement) {
         XmlSchemaElement element = (XmlSchemaElement)particle;
         contentValidator.AddName(element.QualifiedName, element);       
      }
     else if (particle is XmlSchemaAny) {
         hasWildCard = true;
         XmlSchemaAny any = (XmlSchemaAny)particle;
         contentValidator.AddNamespaceList(any.NamespaceList, any);
     }
     else if (particle is XmlSchemaGroupBase) {
         XmlSchemaObjectCollection particles = ((XmlSchemaGroupBase)particle).Items;
         bool isChoice = particle is XmlSchemaChoice;
         contentValidator.OpenGroup();
         bool first = true;
         for (int i = 0; i < particles.Count; ++i) {
             Debug.Assert(!((XmlSchemaParticle)particles[i]).IsEmpty);
             if (first) {
                 first = false;
             }
             else if (isChoice) {
                 contentValidator.AddChoice();  
             }
             else {
                 contentValidator.AddSequence();
             }
             hasWildCard = BuildParticleContentModel(contentValidator, (XmlSchemaParticle)particles[i]);
         }
         contentValidator.CloseGroup();
     }
     else {
         Debug.Assert(false);
     }
     if (particle.MinOccurs == decimal.One && particle.MaxOccurs == decimal.One) {
         // nothing
     }
     else if (particle.MinOccurs == decimal.Zero && particle.MaxOccurs == decimal.One) {
         contentValidator.AddQMark();
     }
     else if (particle.MinOccurs == decimal.Zero && particle.MaxOccurs == decimal.MaxValue) {
         contentValidator.AddStar();
     }
     else if (particle.MinOccurs == decimal.One && particle.MaxOccurs == decimal.MaxValue) {
         contentValidator.AddPlus();
     }
     else {
         contentValidator.AddLeafRange(particle.MinOccurs, particle.MaxOccurs);
     }
     return hasWildCard;
 }
        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;
                }
            }
        }
        private void ParseElementDecl() {

            // element name
            if ( GetToken( true ) != Token.QName ) {
                goto UnexpectedError;
            }

            // get schema decl for element
            SchemaElementDecl elementDecl = null;
            XmlQualifiedName name = GetNameQualified( true );
            elementDecl = (SchemaElementDecl)schemaInfo.ElementDecls[name];

            if ( elementDecl != null ) {
                if ( validate ) {
                    SendValidationEvent( curPos - name.Name.Length, XmlSeverityType.Error, Res.Sch_DupElementDecl, GetNameString() );
                }
            }
            else {
                if ( ( elementDecl = (SchemaElementDecl)schemaInfo.UndeclaredElementDecls[name] ) != null ) {
                    schemaInfo.UndeclaredElementDecls.Remove( name );
                }
                else {
                    elementDecl = new SchemaElementDecl( name, name.Namespace, SchemaType.DTD );
                }
                schemaInfo.ElementDecls.Add( name, elementDecl );
            }
            elementDecl.IsDeclaredInExternal = !ParsingInternalSubset;

            // content spec
            switch ( GetToken( true ) ) {
                case Token.EMPTY:
                    elementDecl.ContentValidator = ContentValidator.Empty;
                    goto End;
                case Token.ANY:
                    elementDecl.ContentValidator = ContentValidator.Any;
                    goto End;
                case Token.LeftParen:
                    int startParenEntityId = currentEntityId;
                    switch ( GetToken( false ) ) {
                        case Token.PCDATA:
                        {
                            ParticleContentValidator pcv = new ParticleContentValidator( XmlSchemaContentType.Mixed );
                            pcv.Start();
                            pcv.OpenGroup();

                            ParseElementMixedContent( pcv, startParenEntityId );

                            elementDecl.ContentValidator = pcv.Finish( true );
                            goto End;
                        }
                        case Token.None:
                        {
                            ParticleContentValidator pcv = null;
                            pcv = new ParticleContentValidator( XmlSchemaContentType.ElementOnly );
                            pcv.Start();
                            pcv.OpenGroup();

                            ParseElementOnlyContent( pcv, startParenEntityId );

                            elementDecl.ContentValidator = pcv.Finish( true );
                            goto End;
                        }
                        default:
                            goto UnexpectedError;
                    }
                default:
                    goto UnexpectedError;
            }
    End:
            if ( GetToken( false ) != Token.GreaterThan ) {
                ThrowUnexpectedToken( curPos, ">" );
            }
            return;

            UnexpectedError:
                OnUnexpectedError();
        }
 private async Task ParseHowManyAsync( ParticleContentValidator pcv ) {
     switch ( await GetTokenAsync( false ).ConfigureAwait(false) ) {
         case Token.Star:
             pcv.AddStar();
             return;
         case Token.QMark:
             pcv.AddQMark();
             return;
         case Token.Plus:
             pcv.AddPlus();
             return;
         default:
             return;
     }
 }
 private static void HandleMinMax(ParticleContentValidator pContent, uint cMin, uint cMax)
 {
     if (pContent != null)
     {
         if (cMax == uint.MaxValue)
         {
             if (cMin == 0)
             {
                 pContent.AddStar();
             }
             else
             {
                 pContent.AddPlus();
             }
         }
         else if (cMin == 0)
         {
             pContent.AddQMark();
         }
     }
 }
 private static XmlSchemaComplexType CreateAnyType(XmlSchemaContentProcessing processContents)
 {
     XmlSchemaComplexType type = new XmlSchemaComplexType();
     type.SetQualifiedName(DatatypeImplementation.QnAnyType);
     XmlSchemaAny item = new XmlSchemaAny {
         MinOccurs = 0M,
         MaxOccurs = 79228162514264337593543950335M,
         ProcessContents = processContents
     };
     item.BuildNamespaceList(null);
     XmlSchemaSequence sequence = new XmlSchemaSequence();
     sequence.Items.Add(item);
     type.SetContentTypeParticle(sequence);
     type.SetContentType(XmlSchemaContentType.Mixed);
     type.ElementDecl = SchemaElementDecl.CreateAnyTypeElementDecl();
     type.ElementDecl.SchemaType = type;
     ParticleContentValidator validator = new ParticleContentValidator(XmlSchemaContentType.Mixed);
     validator.Start();
     validator.OpenGroup();
     validator.AddNamespaceList(item.NamespaceList, item);
     validator.AddStar();
     validator.CloseGroup();
     ContentValidator validator2 = validator.Finish(true);
     type.ElementDecl.ContentValidator = validator2;
     XmlSchemaAnyAttribute attribute = new XmlSchemaAnyAttribute {
         ProcessContents = processContents
     };
     attribute.BuildNamespaceList(null);
     type.SetAttributeWildcard(attribute);
     type.ElementDecl.AnyAttribute = attribute;
     return type;
 }
Beispiel #15
0
        private void ParseElementDecl()
        {
            // element name
            if (GetToken(true) != Token.QName)
            {
                goto UnexpectedError;
            }

            // get schema decl for element
            SchemaElementDecl elementDecl = null;
            XmlQualifiedName name = GetNameQualified(true);

            if (_schemaInfo.ElementDecls.TryGetValue(name, out elementDecl))
            {
#if !SILVERLIGHT
                if (_validate)
                {
                    SendValidationEvent(_curPos - name.Name.Length, XmlSeverityType.Error, SR.Sch_DupElementDecl, GetNameString());
                }
#endif
            }
            else
            {
                if (_schemaInfo.UndeclaredElementDecls.TryGetValue(name, out elementDecl))
                {
                    _schemaInfo.UndeclaredElementDecls.Remove(name);
                }
                else
                {
                    elementDecl = new SchemaElementDecl(name, name.Namespace);
                }
                _schemaInfo.ElementDecls.Add(name, elementDecl);
            }
            elementDecl.IsDeclaredInExternal = !ParsingInternalSubset;

            // content spec
#if SILVERLIGHT
            switch ( GetToken( true ) ) {
                case Token.EMPTY:
                case Token.ANY:
                    break;
                case Token.LeftParen:
                    switch ( GetToken( false ) ) {
                        case Token.PCDATA:
                            ParseElementMixedContentNoValidation();
                            break;
                        case Token.None:
                            ParseElementOnlyContentNoValidation();
                            break;
                        default:
                            goto UnexpectedError;
                    }
                    break;
                default:
                    goto UnexpectedError;
            }
#else
            switch (GetToken(true))
            {
                case Token.EMPTY:
                    elementDecl.ContentValidator = ContentValidator.Empty;
                    break;
                case Token.ANY:
                    elementDecl.ContentValidator = ContentValidator.Any;
                    break;
                case Token.LeftParen:
                    int startParenEntityId = _currentEntityId;
                    switch (GetToken(false))
                    {
                        case Token.PCDATA:
                            {
                                ParticleContentValidator pcv = new ParticleContentValidator(XmlSchemaContentType.Mixed);
                                pcv.Start();
                                pcv.OpenGroup();

                                ParseElementMixedContent(pcv, startParenEntityId);

                                elementDecl.ContentValidator = pcv.Finish(true);
                                break;
                            }
                        case Token.None:
                            {
                                ParticleContentValidator pcv = null;
                                pcv = new ParticleContentValidator(XmlSchemaContentType.ElementOnly);
                                pcv.Start();
                                pcv.OpenGroup();

                                ParseElementOnlyContent(pcv, startParenEntityId);

                                elementDecl.ContentValidator = pcv.Finish(true);
                                break;
                            }
                        default:
                            goto UnexpectedError;
                    }
                    break;
                default:
                    goto UnexpectedError;
            }
#endif
            if (GetToken(false) != Token.GreaterThan)
            {
                ThrowUnexpectedToken(_curPos, ">");
            }
            return;

        UnexpectedError:
            OnUnexpectedError();
        }
        private void ParseElementOnlyContent( ParticleContentValidator pcv, int startParenEntityId ) {
            Token parsingSchema = Token.None;
            int connectorEntityId = startParenEntityId;
            int contentEntityId = -1;

            for (;;) {
                switch ( GetToken( false ) ) {
                    case Token.QName:
        
                        pcv.AddName( GetNameQualified(true), null );

                        if ( validate ) {
                            contentEntityId = currentEntityId;
                            if ( connectorEntityId > contentEntityId ) {  // entity repl.text ending with connector
                                SendValidationEvent( curPos, XmlSeverityType.Error, Res.Sch_ParEntityRefNesting, string.Empty );
                            }
                        }
                        ParseHowMany( pcv );
                        break;
                    case Token.LeftParen:
                        pcv.OpenGroup();
                        if ( validate ) {
                            contentEntityId = currentEntityId;
                            if ( connectorEntityId > contentEntityId ) {  // entity repl.text ending with connector
                                SendValidationEvent( curPos, XmlSeverityType.Error, Res.Sch_ParEntityRefNesting, string.Empty );
                            }
                        }
                        ParseElementOnlyContent( pcv, currentEntityId );
                        break;
                    case Token.GreaterThan:
                        Throw( curPos, Res.Xml_InvalidContentModel );
                        return;
                    default:
                        goto UnexpectedError;
                }

                switch ( GetToken( false ) ) {
                    case Token.Comma:
                        if ( parsingSchema == Token.Or ) {
                            Throw( curPos, Res.Xml_InvalidContentModel );
                        }
                        pcv.AddSequence();
                        parsingSchema = Token.Comma;
                        if ( validate ) {
                            connectorEntityId = currentEntityId;
                            if ( connectorEntityId > contentEntityId ) { // entity repl.text starting with connector
                                SendValidationEvent( curPos, XmlSeverityType.Error, Res.Sch_ParEntityRefNesting, string.Empty );
                            }
                        }
                        break;
                    case Token.Or:
                        if ( parsingSchema == Token.Comma ) {
                            Throw( curPos, Res.Xml_InvalidContentModel );
                        }
                        pcv.AddChoice();
                        parsingSchema = Token.Or;
                        if ( validate ) {
                            connectorEntityId = currentEntityId;
                            if ( connectorEntityId > contentEntityId ) { // entity repl.text starting with connector
                                SendValidationEvent( curPos, XmlSeverityType.Error, Res.Sch_ParEntityRefNesting, string.Empty );
                            }
                        }
                        break;
                    case Token.RightParen:
                        pcv.CloseGroup();
                        if ( validate && currentEntityId != startParenEntityId ) {
                            SendValidationEvent( curPos, XmlSeverityType.Error, Res.Sch_ParEntityRefNesting, string.Empty );
                        }
                        ParseHowMany( pcv );
                        return;
                    case Token.GreaterThan:
                        Throw( curPos, Res.Xml_InvalidContentModel );
                        return;
                    default:
                        goto UnexpectedError;
                }
            }

        UnexpectedError:
            OnUnexpectedError();
        }
 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 void BuildParticleContentModel(ParticleContentValidator contentValidator, XmlSchemaParticle particle) {
     if (particle is XmlSchemaElement) {
         XmlSchemaElement element = (XmlSchemaElement)particle;
         contentValidator.AddName(element.QualifiedName, element);       
     }
     else if (particle is XmlSchemaAny) {
         XmlSchemaAny any = (XmlSchemaAny)particle;
         contentValidator.AddNamespaceList(any.NamespaceList, any);
     }
     else if (particle is XmlSchemaGroupBase) {
         XmlSchemaObjectCollection particles = ((XmlSchemaGroupBase)particle).Items;
         bool isChoice = particle is XmlSchemaChoice;
         contentValidator.OpenGroup();
         bool first = true;
         foreach (XmlSchemaParticle p in particles) {
             Debug.Assert(!p.IsEmpty);
             if (first) {
                 first = false;
             }
             else if (isChoice) {
                 contentValidator.AddChoice();  
             }
             else {
                 contentValidator.AddSequence();
             }
             BuildParticleContentModel(contentValidator, p);
         }
         contentValidator.CloseGroup();
     }
     else {
         Debug.Assert(false);
     }
     if (particle.MinOccurs == decimal.One && particle.MaxOccurs == decimal.One) {
         // nothing
     }
     else if (particle.MinOccurs == decimal.Zero && particle.MaxOccurs == decimal.One) {
         contentValidator.AddQMark();
     }
     else if (particle.MinOccurs == decimal.Zero && particle.MaxOccurs == decimal.MaxValue) {
         contentValidator.AddStar();
     }
     else if (particle.MinOccurs == decimal.One && particle.MaxOccurs == decimal.MaxValue) {
         contentValidator.AddPlus();
     }
     else {
         contentValidator.AddLeafRange(particle.MinOccurs, particle.MaxOccurs);
     }
 }