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;
 }
示例#2
0
 static XmlSchemaComplexType() {
     anyType = new XmlSchemaComplexType();
     anyType.SetContentType(XmlSchemaContentType.Mixed);
     anyType.ElementDecl = SchemaElementDecl.CreateAnyTypeElementDecl();
     XmlSchemaAnyAttribute anyAttribute = new XmlSchemaAnyAttribute();
     anyAttribute.BuildNamespaceList(null);
     anyType.SetAttributeWildcard(anyAttribute);
     anyType.ElementDecl.AnyAttribute = anyAttribute;
 }
 static XmlSchemaComplexType()
 {
     untypedAnyType.SetQualifiedName(new XmlQualifiedName("untypedAny", "http://www.w3.org/2003/11/xpath-datatypes"));
     untypedAnyType.IsMixed = true;
     untypedAnyType.SetContentTypeParticle(anyTypeLax.ContentTypeParticle);
     untypedAnyType.SetContentType(XmlSchemaContentType.Mixed);
     untypedAnyType.ElementDecl = SchemaElementDecl.CreateAnyTypeElementDecl();
     untypedAnyType.ElementDecl.SchemaType = untypedAnyType;
     untypedAnyType.ElementDecl.ContentValidator = AnyTypeContentValidator;
 }
示例#4
0
        static XmlSchemaComplexType()
        {
            anyType = new XmlSchemaComplexType();
            anyType.SetContentType(XmlSchemaContentType.Mixed);
            anyType.ElementDecl = SchemaElementDecl.CreateAnyTypeElementDecl();
            XmlSchemaAnyAttribute anyAttribute = new XmlSchemaAnyAttribute();

            anyAttribute.BuildNamespaceList(null);
            anyType.SetAttributeWildcard(anyAttribute);
            anyType.ElementDecl.AnyAttribute = anyAttribute;
        }
示例#5
0
        //const byte dupDeclMask = 0x08;

        private static XmlSchemaComplexType CreateUntypedAnyType()
        {
            // Create xdt:untypedAny
            var untypedAny = new XmlSchemaComplexType();

            untypedAny.SetQualifiedName(new XmlQualifiedName("untypedAny", XmlReservedNs.NsXQueryDataType));
            untypedAny.IsMixed = true;
            untypedAny.SetContentTypeParticle(s_anyTypeLax.ContentTypeParticle);
            untypedAny.SetContentType(XmlSchemaContentType.Mixed);

            untypedAny.ElementDecl                  = SchemaElementDecl.CreateAnyTypeElementDecl();
            untypedAny.ElementDecl.SchemaType       = untypedAny;
            untypedAny.ElementDecl.ContentValidator = AnyTypeContentValidator;

            return(untypedAny);
        }
示例#6
0
        //const byte dupDeclMask = 0x08;

        static XmlSchemaComplexType()
        {
            anyTypeLax  = CreateAnyType(XmlSchemaContentProcessing.Lax);
            anyTypeSkip = CreateAnyType(XmlSchemaContentProcessing.Skip);

            // Create xdt:untypedAny
            untypedAnyType = new XmlSchemaComplexType();
            untypedAnyType.SetQualifiedName(new XmlQualifiedName("untypedAny", XmlReservedNs.NsXQueryDataType));
            untypedAnyType.IsMixed = true;
            untypedAnyType.SetContentTypeParticle(anyTypeLax.ContentTypeParticle);
            untypedAnyType.SetContentType(XmlSchemaContentType.Mixed);

            untypedAnyType.ElementDecl                  = SchemaElementDecl.CreateAnyTypeElementDecl();
            untypedAnyType.ElementDecl.SchemaType       = untypedAnyType;
            untypedAnyType.ElementDecl.ContentValidator = AnyTypeContentValidator;
        }
        //const byte dupDeclMask = 0x08;

        static XmlSchemaComplexType() {
            anyTypeLax = CreateAnyType(XmlSchemaContentProcessing.Lax);
            anyTypeSkip = CreateAnyType(XmlSchemaContentProcessing.Skip);

            // Create xdt:untypedAny
            untypedAnyType = new XmlSchemaComplexType();
            untypedAnyType.SetQualifiedName(new XmlQualifiedName("untypedAny", XmlReservedNs.NsXQueryDataType));
            untypedAnyType.IsMixed = true;
            untypedAnyType.SetContentTypeParticle(anyTypeLax.ContentTypeParticle);
            untypedAnyType.SetContentType(XmlSchemaContentType.Mixed);

            untypedAnyType.ElementDecl = SchemaElementDecl.CreateAnyTypeElementDecl();
            untypedAnyType.ElementDecl.SchemaType = untypedAnyType;
            untypedAnyType.ElementDecl.ContentValidator = AnyTypeContentValidator;

        }
示例#8
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);
        }
示例#9
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 void CompileComplexType(XmlSchemaComplexType complexType)
 {
     if (complexType.ElementDecl == null)
     {
         if (complexType.IsProcessing)
         {
             base.SendValidationEvent("Sch_TypeCircularRef", complexType);
         }
         else
         {
             complexType.IsProcessing = true;
             if (complexType.ContentModel != null)
             {
                 if (complexType.ContentModel is XmlSchemaSimpleContent)
                 {
                     XmlSchemaSimpleContent contentModel = (XmlSchemaSimpleContent) complexType.ContentModel;
                     complexType.SetContentType(XmlSchemaContentType.TextOnly);
                     if (contentModel.Content is XmlSchemaSimpleContentExtension)
                     {
                         this.CompileSimpleContentExtension(complexType, (XmlSchemaSimpleContentExtension) contentModel.Content);
                     }
                     else
                     {
                         this.CompileSimpleContentRestriction(complexType, (XmlSchemaSimpleContentRestriction) contentModel.Content);
                     }
                 }
                 else
                 {
                     XmlSchemaComplexContent complexContent = (XmlSchemaComplexContent) complexType.ContentModel;
                     if (complexContent.Content is XmlSchemaComplexContentExtension)
                     {
                         this.CompileComplexContentExtension(complexType, complexContent, (XmlSchemaComplexContentExtension) complexContent.Content);
                     }
                     else
                     {
                         this.CompileComplexContentRestriction(complexType, complexContent, (XmlSchemaComplexContentRestriction) complexContent.Content);
                     }
                 }
             }
             else
             {
                 complexType.SetBaseSchemaType(XmlSchemaComplexType.AnyType);
                 this.CompileLocalAttributes(XmlSchemaComplexType.AnyType, complexType, complexType.Attributes, complexType.AnyAttribute, XmlSchemaDerivationMethod.Restriction);
                 complexType.SetDerivedBy(XmlSchemaDerivationMethod.Restriction);
                 complexType.SetContentTypeParticle(this.CompileContentTypeParticle(complexType.Particle, true));
                 complexType.SetContentType(this.GetSchemaContentType(complexType, null, complexType.ContentTypeParticle));
             }
             bool flag = false;
             foreach (XmlSchemaAttribute attribute in complexType.AttributeUses.Values)
             {
                 if (attribute.Use != XmlSchemaUse.Prohibited)
                 {
                     XmlSchemaDatatype datatype = attribute.Datatype;
                     if ((datatype != null) && (datatype.TokenizedType == XmlTokenizedType.ID))
                     {
                         if (flag)
                         {
                             base.SendValidationEvent("Sch_TwoIdAttrUses", complexType);
                         }
                         else
                         {
                             flag = true;
                         }
                     }
                 }
             }
             SchemaElementDecl decl = new SchemaElementDecl {
                 ContentValidator = this.CompileComplexContent(complexType),
                 SchemaType = complexType,
                 IsAbstract = complexType.IsAbstract,
                 Datatype = complexType.Datatype,
                 Block = complexType.BlockResolved,
                 AnyAttribute = complexType.AttributeWildcard
             };
             foreach (XmlSchemaAttribute attribute2 in complexType.AttributeUses.Values)
             {
                 if (attribute2.Use == XmlSchemaUse.Prohibited)
                 {
                     if (!decl.ProhibitedAttributes.ContainsKey(attribute2.QualifiedName))
                     {
                         decl.ProhibitedAttributes.Add(attribute2.QualifiedName, attribute2.QualifiedName);
                     }
                 }
                 else if ((!decl.AttDefs.ContainsKey(attribute2.QualifiedName) && (attribute2.AttDef != null)) && ((attribute2.AttDef.Name != XmlQualifiedName.Empty) && (attribute2.AttDef != SchemaAttDef.Empty)))
                 {
                     decl.AddAttDef(attribute2.AttDef);
                 }
             }
             complexType.ElementDecl = decl;
             complexType.IsProcessing = false;
         }
     }
 }
 private void CompileComplexContentRestriction(XmlSchemaComplexType complexType, XmlSchemaComplexContent complexContent, XmlSchemaComplexContentRestriction complexRestriction)
 {
     XmlSchemaComplexType redefined = null;
     if ((complexType.Redefined != null) && (complexRestriction.BaseTypeName == complexType.Redefined.QualifiedName))
     {
         redefined = (XmlSchemaComplexType) complexType.Redefined;
         this.CompileComplexType(redefined);
     }
     else
     {
         redefined = this.GetComplexType(complexRestriction.BaseTypeName);
         if (redefined == null)
         {
             base.SendValidationEvent("Sch_UndefBaseRestriction", complexRestriction.BaseTypeName.ToString(), complexRestriction);
             return;
         }
     }
     if (((redefined != null) && (redefined.ElementDecl != null)) && (redefined.ContentType == XmlSchemaContentType.TextOnly))
     {
         base.SendValidationEvent("Sch_NotComplexContent", complexType);
     }
     else
     {
         complexType.SetBaseSchemaType(redefined);
         if ((redefined.FinalResolved & XmlSchemaDerivationMethod.Restriction) != XmlSchemaDerivationMethod.Empty)
         {
             base.SendValidationEvent("Sch_BaseFinalRestriction", complexType);
         }
         this.CompileLocalAttributes(redefined, complexType, complexRestriction.Attributes, complexRestriction.AnyAttribute, XmlSchemaDerivationMethod.Restriction);
         complexType.SetContentTypeParticle(this.CompileContentTypeParticle(complexRestriction.Particle, true));
         complexType.SetContentType(this.GetSchemaContentType(complexType, complexContent, complexType.ContentTypeParticle));
         if (complexType.ContentType == XmlSchemaContentType.Empty)
         {
             SchemaElementDecl elementDecl = redefined.ElementDecl;
             if ((redefined.ElementDecl != null) && !redefined.ElementDecl.ContentValidator.IsEmptiable)
             {
                 base.SendValidationEvent("Sch_InvalidContentRestriction", complexType);
             }
         }
         complexType.SetDerivedBy(XmlSchemaDerivationMethod.Restriction);
     }
 }
 private void CompileComplexContentExtension(XmlSchemaComplexType complexType, XmlSchemaComplexContent complexContent, XmlSchemaComplexContentExtension complexExtension)
 {
     XmlSchemaComplexType redefined = null;
     if ((complexType.Redefined != null) && (complexExtension.BaseTypeName == complexType.Redefined.QualifiedName))
     {
         redefined = (XmlSchemaComplexType) complexType.Redefined;
         this.CompileComplexType(redefined);
     }
     else
     {
         redefined = this.GetComplexType(complexExtension.BaseTypeName);
         if (redefined == null)
         {
             base.SendValidationEvent("Sch_UndefBaseExtension", complexExtension.BaseTypeName.ToString(), complexExtension);
             return;
         }
     }
     if (((redefined != null) && (redefined.ElementDecl != null)) && (redefined.ContentType == XmlSchemaContentType.TextOnly))
     {
         base.SendValidationEvent("Sch_NotComplexContent", complexType);
     }
     else
     {
         complexType.SetBaseSchemaType(redefined);
         if ((redefined.FinalResolved & XmlSchemaDerivationMethod.Extension) != XmlSchemaDerivationMethod.Empty)
         {
             base.SendValidationEvent("Sch_BaseFinalExtension", complexType);
         }
         this.CompileLocalAttributes(redefined, complexType, complexExtension.Attributes, complexExtension.AnyAttribute, XmlSchemaDerivationMethod.Extension);
         XmlSchemaParticle contentTypeParticle = redefined.ContentTypeParticle;
         XmlSchemaParticle item = this.CannonicalizeParticle(complexExtension.Particle, true, true);
         if (contentTypeParticle != XmlSchemaParticle.Empty)
         {
             if (item != XmlSchemaParticle.Empty)
             {
                 XmlSchemaSequence particle = new XmlSchemaSequence();
                 particle.Items.Add(contentTypeParticle);
                 particle.Items.Add(item);
                 complexType.SetContentTypeParticle(this.CompileContentTypeParticle(particle, false));
             }
             else
             {
                 complexType.SetContentTypeParticle(contentTypeParticle);
             }
             XmlSchemaContentType contentType = this.GetSchemaContentType(complexType, complexContent, item);
             if (contentType == XmlSchemaContentType.Empty)
             {
                 contentType = redefined.ContentType;
             }
             complexType.SetContentType(contentType);
             if (complexType.ContentType != redefined.ContentType)
             {
                 base.SendValidationEvent("Sch_DifContentType", complexType);
             }
         }
         else
         {
             complexType.SetContentTypeParticle(item);
             complexType.SetContentType(this.GetSchemaContentType(complexType, complexContent, complexType.ContentTypeParticle));
         }
         complexType.SetDerivedBy(XmlSchemaDerivationMethod.Extension);
     }
 }
        private void CompileComplexContentRestriction(XmlSchemaComplexType complexType, XmlSchemaComplexContent complexContent, XmlSchemaComplexContentRestriction complexRestriction) {
            XmlSchemaComplexType baseType = null;
            if (complexType.Redefined != null && complexRestriction.BaseTypeName == complexType.Redefined.QualifiedName) {
                baseType = (XmlSchemaComplexType)complexType.Redefined;
                CompileComplexType(baseType);
            }
            else {
                baseType = GetComplexType(complexRestriction.BaseTypeName);
                if (baseType == null) {
                    SendValidationEvent(Res.Sch_UndefBaseRestriction, complexRestriction.BaseTypeName.ToString(), complexRestriction);   
                    return;
                }
            } 
            complexType.SetBaseSchemaType(baseType);
            if ((baseType.FinalResolved & XmlSchemaDerivationMethod.Restriction) != 0) {
                SendValidationEvent(Res.Sch_BaseFinalRestriction, complexType);
            }
            CompileLocalAttributes(baseType, complexType, complexRestriction.Attributes, complexRestriction.AnyAttribute, XmlSchemaDerivationMethod.Restriction);
            
            complexType.SetContentTypeParticle(CompileContentTypeParticle(complexRestriction.Particle));
            XmlSchemaContentType derivedContentType = GetSchemaContentType(complexType, complexContent, complexType.ContentTypeParticle);
            complexType.SetContentType(derivedContentType);
            switch(derivedContentType) {
                case XmlSchemaContentType.Empty:
                    if (baseType.ElementDecl != null && !baseType.ElementDecl.ContentValidator.IsEmptiable) { //base is either TextOnly or its ElementOnly/Mixed and not emptiable 
                        SendValidationEvent(Res.Sch_InvalidContentRestrictionDetailed, Res.GetString(Res.Sch_InvalidBaseToEmpty), complexType);
                    }
                break;

                case XmlSchemaContentType.Mixed:
                    if (baseType.ContentType != XmlSchemaContentType.Mixed) {
                        SendValidationEvent(Res.Sch_InvalidContentRestrictionDetailed, Res.GetString(Res.Sch_InvalidBaseToMixed), complexType);
                    }
                break;
            }
            complexType.SetDerivedBy(XmlSchemaDerivationMethod.Restriction);
        }
        private void CompileComplexContentExtension(XmlSchemaComplexType complexType, XmlSchemaComplexContent complexContent, XmlSchemaComplexContentExtension complexExtension) {
            XmlSchemaComplexType baseType = null;
            if (complexType.Redefined != null && complexExtension.BaseTypeName == complexType.Redefined.QualifiedName) {
                baseType = (XmlSchemaComplexType)complexType.Redefined;
                CompileComplexType(baseType);
            }
            else {
                baseType = GetComplexType(complexExtension.BaseTypeName);
                if (baseType == null) {
                    SendValidationEvent(Res.Sch_UndefBaseExtension, complexExtension.BaseTypeName.ToString(), complexExtension);   
                    return;
                }
            }
            if ((baseType.FinalResolved & XmlSchemaDerivationMethod.Extension) != 0) {
                SendValidationEvent(Res.Sch_BaseFinalExtension, complexType);
            }
            CompileLocalAttributes(baseType, complexType, complexExtension.Attributes, complexExtension.AnyAttribute, XmlSchemaDerivationMethod.Extension);

            XmlSchemaParticle baseParticle = baseType.ContentTypeParticle;
            XmlSchemaParticle extendedParticle = CannonicalizeParticle(complexExtension.Particle, true);
            if (baseParticle != XmlSchemaParticle.Empty) {
                if (extendedParticle != XmlSchemaParticle.Empty) {
                    XmlSchemaSequence compiledParticle = new XmlSchemaSequence();
                    compiledParticle.Items.Add(baseParticle);
                    compiledParticle.Items.Add(extendedParticle);
                    complexType.SetContentTypeParticle(CompileContentTypeParticle(compiledParticle));
                }
                else {
                    complexType.SetContentTypeParticle(baseParticle);
                }
            }
            else {
                complexType.SetContentTypeParticle(extendedParticle);
            }
            XmlSchemaContentType contentType = GetSchemaContentType(complexType, complexContent, extendedParticle);
            if (contentType == XmlSchemaContentType.Empty) { //Derived content type is empty, Get ContentType from base
                contentType = baseType.ContentType;
                // In case of a simple base type (content type is TextOnly) the derived type
                //   will be the same as the base type. So set the same content type and then also
                //   set the same data type.
                if (contentType == XmlSchemaContentType.TextOnly) {
                    complexType.SetDatatype(baseType.Datatype);
                }
            }
            complexType.SetContentType(contentType);

            if (baseType.ContentType != XmlSchemaContentType.Empty && complexType.ContentType != baseType.ContentType) { //If base is empty, do not check
                SendValidationEvent(Res.Sch_DifContentType, complexType);
                return;
            }
            complexType.SetBaseSchemaType(baseType);
            complexType.SetDerivedBy(XmlSchemaDerivationMethod.Extension);
        }
 private void CompileComplexType(XmlSchemaComplexType complexType) {
     if (complexType.ElementDecl != null) { //already compiled
         return;
     }
     if (complexType.IsProcessing) {
         SendValidationEvent(Res.Sch_TypeCircularRef, complexType);
         return;
     }
     complexType.IsProcessing = true;
     try {
         if (complexType.ContentModel != null) { //simpleContent or complexContent
             if (complexType.ContentModel is XmlSchemaSimpleContent) {
                 XmlSchemaSimpleContent simpleContent = (XmlSchemaSimpleContent)complexType.ContentModel;
                 complexType.SetContentType(XmlSchemaContentType.TextOnly);
                 if (simpleContent.Content is XmlSchemaSimpleContentExtension) {
                     CompileSimpleContentExtension(complexType, (XmlSchemaSimpleContentExtension)simpleContent.Content);
                 }
                 else { //simpleContent.Content is XmlSchemaSimpleContentRestriction
                     CompileSimpleContentRestriction(complexType, (XmlSchemaSimpleContentRestriction)simpleContent.Content);
                 }
             }
             else { // complexType.ContentModel is XmlSchemaComplexContent
                 XmlSchemaComplexContent complexContent = (XmlSchemaComplexContent)complexType.ContentModel;
                 if (complexContent.Content is XmlSchemaComplexContentExtension) {
                     CompileComplexContentExtension(complexType, complexContent, (XmlSchemaComplexContentExtension)complexContent.Content);
                 }
                 else { // complexContent.Content is XmlSchemaComplexContentRestriction
                     CompileComplexContentRestriction(complexType, complexContent, (XmlSchemaComplexContentRestriction)complexContent.Content);
                 }
             }
         }
         else { //equals XmlSchemaComplexContent with baseType is anyType
                 complexType.SetBaseSchemaType(XmlSchemaComplexType.AnyType);
                 CompileLocalAttributes(XmlSchemaComplexType.AnyType, complexType, complexType.Attributes, complexType.AnyAttribute, XmlSchemaDerivationMethod.Restriction);
                 complexType.SetDerivedBy(XmlSchemaDerivationMethod.Restriction);
                 complexType.SetContentTypeParticle(CompileContentTypeParticle(complexType.Particle));
                 complexType.SetContentType(GetSchemaContentType(complexType, null, complexType.ContentTypeParticle));
         }
         if (complexType.ContainsIdAttribute(true)) {
             SendValidationEvent(Res.Sch_TwoIdAttrUses, complexType);
         }
         SchemaElementDecl decl = new SchemaElementDecl();
         decl.ContentValidator = CompileComplexContent(complexType);
         decl.SchemaType = complexType;
         decl.IsAbstract = complexType.IsAbstract;
         decl.Datatype = complexType.Datatype;
         decl.Block = complexType.BlockResolved;
         decl.AnyAttribute = complexType.AttributeWildcard;
         foreach(XmlSchemaAttribute attribute in complexType.AttributeUses.Values) {
             if (attribute.Use == XmlSchemaUse.Prohibited) {
                 if (!decl.ProhibitedAttributes.ContainsKey(attribute.QualifiedName)) {
                     decl.ProhibitedAttributes.Add(attribute.QualifiedName, attribute.QualifiedName);
                 }
             }
             else {
                 if (!decl.AttDefs.ContainsKey(attribute.QualifiedName) && attribute.AttDef != null && attribute.AttDef.Name != XmlQualifiedName.Empty && attribute.AttDef != SchemaAttDef.Empty) {
                     decl.AddAttDef(attribute.AttDef);
                 }
             }
         }
         complexType.ElementDecl = decl;
     }
     finally {
         complexType.IsProcessing = false;
     }
 }
 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;
 }
示例#17
0
        private void CompileComplexType(XmlSchemaComplexType complexType) {
            if (complexType.ElementDecl != null) { //already compiled
                return;
            }
            if (complexType.Validating) {
                SendValidationEvent(Res.Sch_TypeCircularRef, complexType);
                return;
            }
            complexType.Validating = true;

            CompiledContentModel compiledContentModel = new CompiledContentModel(this.schemaNames);
            if (complexType.ContentModel != null) { //simpleContent or complexContent
                if (complexType.ContentModel is XmlSchemaSimpleContent) {
                    XmlSchemaSimpleContent simpleContent = (XmlSchemaSimpleContent)complexType.ContentModel;
                    complexType.SetContentType(XmlSchemaContentType.TextOnly);
                    if (simpleContent.Content is XmlSchemaSimpleContentExtension) {
                        CompileSimpleContentExtension(complexType, (XmlSchemaSimpleContentExtension)simpleContent.Content);
                    }
                    else { //simpleContent.Content is XmlSchemaSimpleContentRestriction
                        CompileSimpleContentRestriction(complexType, (XmlSchemaSimpleContentRestriction)simpleContent.Content);
                    }
                }
                else { // complexType.ContentModel is XmlSchemaComplexContent
                    XmlSchemaComplexContent complexContent = (XmlSchemaComplexContent)complexType.ContentModel;
                    if (complexContent.Content is XmlSchemaComplexContentExtension) {
                        CompileComplexContentExtension(complexType, complexContent, (XmlSchemaComplexContentExtension)complexContent.Content);
                    }
                    else { // complexContent.Content is XmlSchemaComplexContentRestriction
                        CompileComplexContentRestriction(complexType, complexContent, (XmlSchemaComplexContentRestriction)complexContent.Content);
                    }
                    CompileComplexContent(complexType, compiledContentModel);
                }
            }
            else { //equals XmlSchemaComplexContent with baseType is anyType
                CompileLocalAttributes(XmlSchemaComplexType.AnyType, complexType, complexType.Attributes, complexType.AnyAttribute, XmlSchemaDerivationMethod.Restriction);
                complexType.SetDerivedBy(XmlSchemaDerivationMethod.Restriction);
                complexType.SetContentTypeParticle(CompileContentTypeParticle(complexType.Particle, true));
                complexType.SetContentType(GetSchemaContentType(complexType, null, complexType.ContentTypeParticle));
                CompileComplexContent(complexType, compiledContentModel);
            }
            bool hasID = false;
            foreach(XmlSchemaAttribute attribute in complexType.AttributeUses.Values) {
                if (attribute.Use != XmlSchemaUse.Prohibited) {
                    XmlSchemaDatatype datatype = attribute.Datatype;
                    if (datatype != null && datatype.TokenizedType == XmlTokenizedType.ID) {
                        if (hasID) {
                            SendValidationEvent(Res.Sch_TwoIdAttrUses, complexType);
                        }
                        else {
                            hasID = true;
                        }
                    }
                }
            }

            SchemaElementDecl decl = new SchemaElementDecl();
            decl.Content = compiledContentModel;
            decl.Content = compiledContentModel;
            decl.SchemaType = complexType;
            decl.Datatype = complexType.Datatype;
            decl.Block = complexType.BlockResolved;
            switch (complexType.ContentType) {
                case XmlSchemaContentType.TextOnly :    decl.Content.ContentType = CompiledContentModel.Type.Text;          break;
                case XmlSchemaContentType.Empty :       decl.Content.ContentType = CompiledContentModel.Type.Empty;         break;
                case XmlSchemaContentType.ElementOnly : decl.Content.ContentType = CompiledContentModel.Type.ElementOnly;   break;
                default:                                decl.Content.ContentType = CompiledContentModel.Type.Mixed;         break;
            }
            decl.AnyAttribute = complexType.AttributeWildcard;
            foreach(XmlSchemaAttribute attribute in complexType.AttributeUses.Values) {
                if (attribute.Use == XmlSchemaUse.Prohibited) {
                    if (decl.ProhibitedAttributes[attribute.QualifiedName] == null) {
                        decl.ProhibitedAttributes.Add(attribute.QualifiedName, attribute.QualifiedName);
                    }
                }
                else {
                    if (decl.AttDefs[attribute.QualifiedName] == null && attribute.AttDef != null && attribute.AttDef != SchemaAttDef.Empty) {
                        decl.AddAttDef(attribute.AttDef);
                    }
                }
            }
            complexType.ElementDecl = decl;

            complexType.Validating = false;
        }
示例#18
0
        private void CompileComplexContentExtension(XmlSchemaComplexType complexType, XmlSchemaComplexContent complexContent, XmlSchemaComplexContentExtension complexExtension) {
            XmlSchemaComplexType baseType = null;
            if (complexType.Redefined != null && complexExtension.BaseTypeName == complexType.Redefined.QualifiedName) {
                baseType = (XmlSchemaComplexType)complexType.Redefined;
                CompileComplexType(baseType);
            }
            else {
                baseType = GetComplexType(complexExtension.BaseTypeName);
                if (baseType == null) {
                    SendValidationEvent(Res.Sch_UndefBaseExtension, complexExtension.BaseTypeName.ToString(), complexExtension);   
                    return;
                }
            }
            if (baseType != null && baseType.ElementDecl != null) {
                if (baseType.ContentType == XmlSchemaContentType.TextOnly) {
                    SendValidationEvent(Res.Sch_NotComplexContent, complexType);
                }
            }
            complexType.SetBaseSchemaType(baseType);
            if ((baseType.FinalResolved & XmlSchemaDerivationMethod.Extension) != 0) {
                SendValidationEvent(Res.Sch_BaseFinalExtension, complexType);
            }
            CompileLocalAttributes(baseType, complexType, complexExtension.Attributes, complexExtension.AnyAttribute, XmlSchemaDerivationMethod.Extension);

            XmlSchemaParticle baseParticle = baseType.ContentTypeParticle;
            XmlSchemaParticle extendedParticle = CannonicalizeParticle(complexExtension.Particle, true, true);
            if (baseParticle != XmlSchemaParticle.Empty) {
                if (extendedParticle != XmlSchemaParticle.Empty) {
                    XmlSchemaSequence compiledParticle = new XmlSchemaSequence();
                    compiledParticle.Items.Add(baseParticle);
                    compiledParticle.Items.Add(extendedParticle);
                    complexType.SetContentTypeParticle(CompileContentTypeParticle(compiledParticle, false));
                }
                else {
                    complexType.SetContentTypeParticle(baseParticle);
                }
                complexType.SetContentType(GetSchemaContentType(complexType, complexContent, complexType.ContentTypeParticle));
                if (complexType.ContentType != baseType.ContentType) {
                    SendValidationEvent(Res.Sch_DifContentType, complexType);
                }
            }
            else {
                complexType.SetContentTypeParticle(extendedParticle);
                complexType.SetContentType(GetSchemaContentType(complexType, complexContent, complexType.ContentTypeParticle));
            }
            complexType.SetDerivedBy(XmlSchemaDerivationMethod.Extension);
        }
        private void CompileComplexContentRestriction(XmlSchemaComplexType complexType, XmlSchemaComplexContent complexContent, XmlSchemaComplexContentRestriction complexRestriction)
        {
            XmlSchemaComplexType redefined = null;
            if ((complexType.Redefined != null) && (complexRestriction.BaseTypeName == complexType.Redefined.QualifiedName))
            {
                redefined = (XmlSchemaComplexType) complexType.Redefined;
                this.CompileComplexType(redefined);
            }
            else
            {
                redefined = this.GetComplexType(complexRestriction.BaseTypeName);
                if (redefined == null)
                {
                    base.SendValidationEvent("Sch_UndefBaseRestriction", complexRestriction.BaseTypeName.ToString(), complexRestriction);
                    return;
                }
            }
            complexType.SetBaseSchemaType(redefined);
            if ((redefined.FinalResolved & XmlSchemaDerivationMethod.Restriction) != XmlSchemaDerivationMethod.Empty)
            {
                base.SendValidationEvent("Sch_BaseFinalRestriction", complexType);
            }
            this.CompileLocalAttributes(redefined, complexType, complexRestriction.Attributes, complexRestriction.AnyAttribute, XmlSchemaDerivationMethod.Restriction);
            complexType.SetContentTypeParticle(this.CompileContentTypeParticle(complexRestriction.Particle));
            XmlSchemaContentType type2 = this.GetSchemaContentType(complexType, complexContent, complexType.ContentTypeParticle);
            complexType.SetContentType(type2);
            switch (type2)
            {
                case XmlSchemaContentType.Empty:
                    if ((redefined.ElementDecl != null) && !redefined.ElementDecl.ContentValidator.IsEmptiable)
                    {
                        base.SendValidationEvent("Sch_InvalidContentRestrictionDetailed", Res.GetString("Sch_InvalidBaseToEmpty"), complexType);
                    }
                    break;

                case XmlSchemaContentType.Mixed:
                    if (redefined.ContentType != XmlSchemaContentType.Mixed)
                    {
                        base.SendValidationEvent("Sch_InvalidContentRestrictionDetailed", Res.GetString("Sch_InvalidBaseToMixed"), complexType);
                    }
                    break;
            }
            complexType.SetDerivedBy(XmlSchemaDerivationMethod.Restriction);
        }
 private void CompileComplexContentRestriction(XmlSchemaComplexType complexType, XmlSchemaComplexContent complexContent, XmlSchemaComplexContentRestriction complexRestriction) {
     XmlSchemaComplexType baseType = null;
     if (complexType.Redefined != null && complexRestriction.BaseTypeName == complexType.Redefined.QualifiedName) {
         baseType = (XmlSchemaComplexType)complexType.Redefined;
         CompileComplexType(baseType);
     }
     else {
         baseType = GetComplexType(complexRestriction.BaseTypeName);
         if (baseType == null) {
             SendValidationEvent(Res.Sch_UndefBaseRestriction, complexRestriction.BaseTypeName.ToString(), complexRestriction);   
             return;
         }
     } 
     if (baseType != null && baseType.ElementDecl != null) {
         if (baseType.ContentType == XmlSchemaContentType.TextOnly) {
             SendValidationEvent(Res.Sch_NotComplexContent, complexType);
             return;
         }
     }
     complexType.SetBaseSchemaType(baseType);
     if ((baseType.FinalResolved & XmlSchemaDerivationMethod.Restriction) != 0) {
         SendValidationEvent(Res.Sch_BaseFinalRestriction, complexType);
     }
     CompileLocalAttributes(baseType, complexType, complexRestriction.Attributes, complexRestriction.AnyAttribute, XmlSchemaDerivationMethod.Restriction);
     
     complexType.SetContentTypeParticle(CompileContentTypeParticle(complexRestriction.Particle, true));
     complexType.SetContentType(GetSchemaContentType(complexType, complexContent, complexType.ContentTypeParticle));
     if (complexType.ContentType == XmlSchemaContentType.Empty) {
         if (baseType.ElementDecl != null) {
             Debug.Assert(baseType.ElementDecl.ContentValidator != null);
         }
         if (baseType.ElementDecl != null && !baseType.ElementDecl.ContentValidator.IsEmptiable) {
             SendValidationEvent(Res.Sch_InvalidContentRestriction, complexType);
         }
     }
     complexType.SetDerivedBy(XmlSchemaDerivationMethod.Restriction);
 }