Finish() public method

public Finish ( ) : ContentValidator
return ContentValidator
 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;
 }
Example #2
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;
        }
 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;
     }
 }
Example #5
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 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 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;
 }