SetAttributeWildcard() private méthode

private SetAttributeWildcard ( XmlSchemaAnyAttribute value ) : void
value XmlSchemaAnyAttribute
Résultat void
 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;
 }
 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;
 }
Exemple #3
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;
        }
Exemple #4
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 void CleanupComplexType(XmlSchemaComplexType complexType)
 {
     if (complexType.ContentModel != null)
     {
         if (complexType.ContentModel is XmlSchemaSimpleContent)
         {
             XmlSchemaSimpleContent contentModel = (XmlSchemaSimpleContent) complexType.ContentModel;
             if (contentModel.Content is XmlSchemaSimpleContentExtension)
             {
                 XmlSchemaSimpleContentExtension content = (XmlSchemaSimpleContentExtension) contentModel.Content;
                 CleanupAttributes(content.Attributes);
             }
             else
             {
                 XmlSchemaSimpleContentRestriction restriction = (XmlSchemaSimpleContentRestriction) contentModel.Content;
                 CleanupAttributes(restriction.Attributes);
             }
         }
         else
         {
             XmlSchemaComplexContent content2 = (XmlSchemaComplexContent) complexType.ContentModel;
             if (content2.Content is XmlSchemaComplexContentExtension)
             {
                 XmlSchemaComplexContentExtension extension2 = (XmlSchemaComplexContentExtension) content2.Content;
                 CleanupParticle(extension2.Particle);
                 CleanupAttributes(extension2.Attributes);
             }
             else
             {
                 XmlSchemaComplexContentRestriction restriction2 = (XmlSchemaComplexContentRestriction) content2.Content;
                 CleanupParticle(restriction2.Particle);
                 CleanupAttributes(restriction2.Attributes);
             }
         }
     }
     else
     {
         CleanupParticle(complexType.Particle);
         CleanupAttributes(complexType.Attributes);
     }
     complexType.LocalElements.Clear();
     complexType.AttributeUses.Clear();
     complexType.SetAttributeWildcard(null);
     complexType.SetContentTypeParticle(XmlSchemaParticle.Empty);
     complexType.ElementDecl = null;
 }
 private void CompileLocalAttributes(XmlSchemaComplexType baseType, XmlSchemaComplexType derivedType, XmlSchemaObjectCollection attributes, XmlSchemaAnyAttribute anyAttribute, XmlSchemaDerivationMethod derivedBy)
 {
     XmlSchemaAnyAttribute b = (baseType != null) ? baseType.AttributeWildcard : null;
     for (int i = 0; i < attributes.Count; i++)
     {
         XmlSchemaAttribute xa = attributes[i] as XmlSchemaAttribute;
         if (xa != null)
         {
             if (xa.Use != XmlSchemaUse.Prohibited)
             {
                 this.CompileAttribute(xa);
             }
             if ((xa.Use != XmlSchemaUse.Prohibited) || (((xa.Use == XmlSchemaUse.Prohibited) && (derivedBy == XmlSchemaDerivationMethod.Restriction)) && (baseType != XmlSchemaComplexType.AnyType)))
             {
                 if (derivedType.AttributeUses[xa.QualifiedName] == null)
                 {
                     derivedType.AttributeUses.Add(xa.QualifiedName, xa);
                 }
                 else
                 {
                     base.SendValidationEvent("Sch_DupAttributeUse", xa.QualifiedName.ToString(), xa);
                 }
             }
             else
             {
                 base.SendValidationEvent("Sch_AttributeIgnored", xa.QualifiedName.ToString(), xa, XmlSeverityType.Warning);
             }
         }
         else
         {
             XmlSchemaAttributeGroupRef source = (XmlSchemaAttributeGroupRef) attributes[i];
             XmlSchemaAttributeGroup attributeGroup = (XmlSchemaAttributeGroup) this.schema.AttributeGroups[source.RefName];
             if (attributeGroup != null)
             {
                 this.CompileAttributeGroup(attributeGroup);
                 foreach (XmlSchemaAttribute attribute3 in attributeGroup.AttributeUses.Values)
                 {
                     if ((attribute3.Use != XmlSchemaUse.Prohibited) || (((attribute3.Use == XmlSchemaUse.Prohibited) && (derivedBy == XmlSchemaDerivationMethod.Restriction)) && (baseType != XmlSchemaComplexType.AnyType)))
                     {
                         if (derivedType.AttributeUses[attribute3.QualifiedName] == null)
                         {
                             derivedType.AttributeUses.Add(attribute3.QualifiedName, attribute3);
                         }
                         else
                         {
                             base.SendValidationEvent("Sch_DupAttributeUse", attribute3.QualifiedName.ToString(), source);
                         }
                     }
                     else
                     {
                         base.SendValidationEvent("Sch_AttributeIgnored", attribute3.QualifiedName.ToString(), attribute3, XmlSeverityType.Warning);
                     }
                 }
                 anyAttribute = this.CompileAnyAttributeIntersection(anyAttribute, attributeGroup.AttributeWildcard);
             }
             else
             {
                 base.SendValidationEvent("Sch_UndefAttributeGroupRef", source.RefName.ToString(), source);
             }
         }
     }
     if (baseType != null)
     {
         if (derivedBy == XmlSchemaDerivationMethod.Extension)
         {
             derivedType.SetAttributeWildcard(this.CompileAnyAttributeUnion(anyAttribute, b));
             foreach (XmlSchemaAttribute attribute4 in baseType.AttributeUses.Values)
             {
                 XmlSchemaAttribute attribute5 = (XmlSchemaAttribute) derivedType.AttributeUses[attribute4.QualifiedName];
                 if (attribute5 != null)
                 {
                     if ((attribute5.AttributeSchemaType != attribute4.AttributeSchemaType) || (attribute4.Use == XmlSchemaUse.Prohibited))
                     {
                         base.SendValidationEvent("Sch_InvalidAttributeExtension", attribute5);
                     }
                 }
                 else
                 {
                     derivedType.AttributeUses.Add(attribute4.QualifiedName, attribute4);
                 }
             }
         }
         else
         {
             if ((anyAttribute != null) && ((b == null) || !XmlSchemaAnyAttribute.IsSubset(anyAttribute, b)))
             {
                 base.SendValidationEvent("Sch_InvalidAnyAttributeRestriction", derivedType);
             }
             else
             {
                 derivedType.SetAttributeWildcard(anyAttribute);
             }
             foreach (XmlSchemaAttribute attribute6 in baseType.AttributeUses.Values)
             {
                 XmlSchemaAttribute attribute7 = (XmlSchemaAttribute) derivedType.AttributeUses[attribute6.QualifiedName];
                 if (attribute7 == null)
                 {
                     derivedType.AttributeUses.Add(attribute6.QualifiedName, attribute6);
                 }
                 else if ((attribute6.Use == XmlSchemaUse.Prohibited) && (attribute7.Use != XmlSchemaUse.Prohibited))
                 {
                     base.SendValidationEvent("Sch_AttributeRestrictionProhibited", attribute7);
                 }
                 else if ((attribute7.Use != XmlSchemaUse.Prohibited) && (((attribute6.AttributeSchemaType == null) || (attribute7.AttributeSchemaType == null)) || !XmlSchemaType.IsDerivedFrom(attribute7.AttributeSchemaType, attribute6.AttributeSchemaType, XmlSchemaDerivationMethod.Empty)))
                 {
                     base.SendValidationEvent("Sch_AttributeRestrictionInvalid", attribute7);
                 }
             }
             foreach (XmlSchemaAttribute attribute8 in derivedType.AttributeUses.Values)
             {
                 if ((((XmlSchemaAttribute) baseType.AttributeUses[attribute8.QualifiedName]) == null) && ((b == null) || !b.Allows(attribute8.QualifiedName)))
                 {
                     base.SendValidationEvent("Sch_AttributeRestrictionInvalidFromWildcard", attribute8);
                 }
             }
         }
     }
     else
     {
         derivedType.SetAttributeWildcard(anyAttribute);
     }
 }
        private void CleanupComplexType(XmlSchemaComplexType complexType) {
            if (complexType.QualifiedName == DatatypeImplementation.QnAnyType) { //if it is built-in anyType dont clean it.
                return;
            }
            if (complexType.ContentModel != null) { //simpleContent or complexContent
                if (complexType.ContentModel is XmlSchemaSimpleContent) {
                    XmlSchemaSimpleContent simpleContent = (XmlSchemaSimpleContent)complexType.ContentModel;
                    if (simpleContent.Content is XmlSchemaSimpleContentExtension) {
                        XmlSchemaSimpleContentExtension simpleExtension = (XmlSchemaSimpleContentExtension)simpleContent.Content;
                        CleanupAttributes(simpleExtension.Attributes);
                    }
                    else { //simpleContent.Content is XmlSchemaSimpleContentRestriction
                        XmlSchemaSimpleContentRestriction simpleRestriction = (XmlSchemaSimpleContentRestriction)simpleContent.Content;
                        CleanupAttributes(simpleRestriction.Attributes);
                    }
                }
                else { // complexType.ContentModel is XmlSchemaComplexContent
                    XmlSchemaComplexContent complexContent = (XmlSchemaComplexContent)complexType.ContentModel;
                    if (complexContent.Content is XmlSchemaComplexContentExtension) {
                        XmlSchemaComplexContentExtension complexExtension = (XmlSchemaComplexContentExtension)complexContent.Content;
                        CleanupParticle(complexExtension.Particle);
                        CleanupAttributes(complexExtension.Attributes);

                    }
                    else { //XmlSchemaComplexContentRestriction
                        XmlSchemaComplexContentRestriction complexRestriction = (XmlSchemaComplexContentRestriction)complexContent.Content;
                        CleanupParticle(complexRestriction.Particle);
                        CleanupAttributes(complexRestriction.Attributes);
                    }
                }
            }
            else { //equals XmlSchemaComplexContent with baseType is anyType
                CleanupParticle(complexType.Particle);
                CleanupAttributes(complexType.Attributes);
            }
            complexType.LocalElements.Clear();
            complexType.AttributeUses.Clear();
            complexType.SetAttributeWildcard(null);
            complexType.SetContentTypeParticle(XmlSchemaParticle.Empty);
            complexType.ElementDecl = null;
            complexType.HasWildCard = false;

            //Clean up the original type if this is a redefined type
            if (complexType.Redefined != null) {
                CleanupComplexType(complexType.Redefined as XmlSchemaComplexType);
            }
        }
        private void CompileLocalAttributes(XmlSchemaComplexType baseType, XmlSchemaComplexType derivedType, XmlSchemaObjectCollection attributes, XmlSchemaAnyAttribute anyAttribute, XmlSchemaDerivationMethod derivedBy) {
            XmlSchemaAnyAttribute baseAttributeWildcard = baseType != null ? baseType.AttributeWildcard : null;  
            for (int i = 0; i < attributes.Count; ++i) {
                XmlSchemaAttribute attr = attributes[i] as XmlSchemaAttribute;
                if (attr != null) {
                    if (attr.Use != XmlSchemaUse.Prohibited) {
                        CompileAttribute(attr);
                    }
                    if (attr.Use != XmlSchemaUse.Prohibited || 
                        (attr.Use == XmlSchemaUse.Prohibited && derivedBy == XmlSchemaDerivationMethod.Restriction && baseType != XmlSchemaComplexType.AnyType)) {

                        if (derivedType.AttributeUses[attr.QualifiedName] == null) {
                            derivedType.AttributeUses.Add(attr.QualifiedName, attr);
                        }
                        else  {
                            SendValidationEvent(Res.Sch_DupAttributeUse, attr.QualifiedName.ToString(), attr);
                        }
                    }
                    else {
                        SendValidationEvent(Res.Sch_AttributeIgnored, attr.QualifiedName.ToString(), attr, XmlSeverityType.Warning);
                    }

                }
                else { // is XmlSchemaAttributeGroupRef
                    XmlSchemaAttributeGroupRef attributeGroupRef = (XmlSchemaAttributeGroupRef) attributes[i];
                    XmlSchemaAttributeGroup attributeGroup = (XmlSchemaAttributeGroup)attributeGroups[attributeGroupRef.RefName];
                    if (attributeGroup != null) {
                        CompileAttributeGroup(attributeGroup);
                        foreach (XmlSchemaAttribute attribute in attributeGroup.AttributeUses.Values) {
                          if (attribute.Use != XmlSchemaUse.Prohibited || 
                             (attribute.Use == XmlSchemaUse.Prohibited && derivedBy == XmlSchemaDerivationMethod.Restriction && baseType != XmlSchemaComplexType.AnyType)) {
                            if (derivedType.AttributeUses[attribute.QualifiedName] == null) {
                                derivedType.AttributeUses.Add(attribute.QualifiedName, attribute);
                            }
                            else {
                                SendValidationEvent(Res.Sch_DupAttributeUse, attribute.QualifiedName.ToString(), attributeGroupRef);
                            }
                          }
                          else {
                            SendValidationEvent(Res.Sch_AttributeIgnored, attribute.QualifiedName.ToString(), attribute, XmlSeverityType.Warning);
                          }

                        }
                        anyAttribute = CompileAnyAttributeIntersection(anyAttribute, attributeGroup.AttributeWildcard);
                    }
                    else {
                        SendValidationEvent(Res.Sch_UndefAttributeGroupRef, attributeGroupRef.RefName.ToString(), attributeGroupRef);
                    }
                }
            }

            // check derivation rules
            if (baseType != null) {
                if (derivedBy == XmlSchemaDerivationMethod.Extension) {
                    derivedType.SetAttributeWildcard(CompileAnyAttributeUnion(anyAttribute, baseAttributeWildcard));
                    foreach(XmlSchemaAttribute attributeBase in baseType.AttributeUses.Values) {
                        XmlSchemaAttribute attribute = (XmlSchemaAttribute)derivedType.AttributeUses[attributeBase.QualifiedName];
                        if (attribute == null) {
                            derivedType.AttributeUses.Add(attributeBase.QualifiedName, attributeBase);
                        }
                        else {
                            Debug.Assert(attribute.Use != XmlSchemaUse.Prohibited);
                            if (attributeBase.Use != XmlSchemaUse.Prohibited && attribute.AttributeSchemaType != attributeBase.AttributeSchemaType) { //Extension allows previously prohibited attributes to be re-added, 
                                SendValidationEvent(Res.Sch_InvalidAttributeExtension, attribute);
                            }
                        }
                    }
                }
                else {  // derivedBy == XmlSchemaDerivationMethod.Restriction
                    // Schema Component Constraint: Derivation Valid (Restriction, Complex)
                    if ((anyAttribute != null) && (baseAttributeWildcard == null || !XmlSchemaAnyAttribute.IsSubset(anyAttribute, baseAttributeWildcard) || !IsProcessContentsRestricted(baseType, anyAttribute, baseAttributeWildcard)) ) {
                        SendValidationEvent(Res.Sch_InvalidAnyAttributeRestriction, derivedType);
                    }
                    else {
                        derivedType.SetAttributeWildcard(anyAttribute); //complete wildcard
                    }

                    // Add form the base
                    foreach(XmlSchemaAttribute attributeBase in baseType.AttributeUses.Values) {
                        XmlSchemaAttribute attribute = (XmlSchemaAttribute)derivedType.AttributeUses[attributeBase.QualifiedName];
                        if (attribute == null) {
                            derivedType.AttributeUses.Add(attributeBase.QualifiedName, attributeBase);
                        } 
                        else {
                            if (attributeBase.Use == XmlSchemaUse.Prohibited && attribute.Use != XmlSchemaUse.Prohibited) {
#if DEBUG
                                string position = string.Empty;
                                if (derivedType.SourceUri != null) {
                                    position = " in " + derivedType.SourceUri + "(" + derivedType.LineNumber + ", " + derivedType.LinePosition + ")";
                                }
                                Debug.WriteLineIf(DiagnosticsSwitches.XmlSchema.TraceError, "Invalid complexType attributes restriction" + position);
                                Debug.WriteLineIf(DiagnosticsSwitches.XmlSchema.TraceError, "     Base    " + DumpAttributes(baseType.AttributeUses, baseType.AttributeWildcard));
                                Debug.WriteLineIf(DiagnosticsSwitches.XmlSchema.TraceError, "     Derived " + DumpAttributes(derivedType.AttributeUses, derivedType.AttributeWildcard));
#endif
                                SendValidationEvent(Res.Sch_AttributeRestrictionProhibited, attribute);
                            } 
                            else if (attributeBase.Use == XmlSchemaUse.Required && (attribute.Use != XmlSchemaUse.Required)) { //If base is required, derived should also be required
                                SendValidationEvent(Res.Sch_AttributeUseInvalid, attribute);
                            }
                            else if (attribute.Use == XmlSchemaUse.Prohibited) {
                                continue;
                            }
                            else if (attributeBase.AttributeSchemaType == null || attribute.AttributeSchemaType == null || !XmlSchemaType.IsDerivedFrom(attribute.AttributeSchemaType, attributeBase.AttributeSchemaType, XmlSchemaDerivationMethod.Empty)) {
                                SendValidationEvent(Res.Sch_AttributeRestrictionInvalid, attribute);
                            }
                            else if (!IsFixedEqual(attributeBase.AttDef, attribute.AttDef)) {
                                SendValidationEvent(Res.Sch_AttributeFixedInvalid, attribute);
                            }
                        }
                    }

                    // Check additional ones are valid restriction of base's wildcard
                    foreach(XmlSchemaAttribute attribute in derivedType.AttributeUses.Values) {
                        XmlSchemaAttribute attributeBase = (XmlSchemaAttribute)baseType.AttributeUses[attribute.QualifiedName];
                        if (attributeBase != null) {
                            continue;
                        }
                        if (baseAttributeWildcard == null || !baseAttributeWildcard.Allows(attribute.QualifiedName)) {
#if DEBUG
                            string position = string.Empty;
                            if (derivedType.SourceUri != null) {
                                position = " in " + derivedType.SourceUri + "(" + derivedType.LineNumber + ", " + derivedType.LinePosition + ")";
                            }
                            Debug.WriteLineIf(DiagnosticsSwitches.XmlSchema.TraceError, "Invalid complexType attributes restriction" + position);
                            Debug.WriteLineIf(DiagnosticsSwitches.XmlSchema.TraceError, "     Base    " + DumpAttributes(baseType.AttributeUses, baseType.AttributeWildcard));
                            Debug.WriteLineIf(DiagnosticsSwitches.XmlSchema.TraceError, "     Derived " + DumpAttributes(derivedType.AttributeUses, derivedType.AttributeWildcard));
#endif
                            SendValidationEvent(Res.Sch_AttributeRestrictionInvalidFromWildcard, attribute);
                        }
                    }
                }
            } 
            else {
                derivedType.SetAttributeWildcard(anyAttribute);
            }
       }
        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 CleanupComplexType(XmlSchemaComplexType complexType)
 {
     if (complexType.QualifiedName != DatatypeImplementation.QnAnyType)
     {
         if (complexType.ContentModel != null)
         {
             if (complexType.ContentModel is XmlSchemaSimpleContent)
             {
                 XmlSchemaSimpleContent contentModel = (XmlSchemaSimpleContent) complexType.ContentModel;
                 if (contentModel.Content is XmlSchemaSimpleContentExtension)
                 {
                     XmlSchemaSimpleContentExtension content = (XmlSchemaSimpleContentExtension) contentModel.Content;
                     this.CleanupAttributes(content.Attributes);
                 }
                 else
                 {
                     XmlSchemaSimpleContentRestriction restriction = (XmlSchemaSimpleContentRestriction) contentModel.Content;
                     this.CleanupAttributes(restriction.Attributes);
                 }
             }
             else
             {
                 XmlSchemaComplexContent content2 = (XmlSchemaComplexContent) complexType.ContentModel;
                 if (content2.Content is XmlSchemaComplexContentExtension)
                 {
                     XmlSchemaComplexContentExtension extension2 = (XmlSchemaComplexContentExtension) content2.Content;
                     this.CleanupParticle(extension2.Particle);
                     this.CleanupAttributes(extension2.Attributes);
                 }
                 else
                 {
                     XmlSchemaComplexContentRestriction restriction2 = (XmlSchemaComplexContentRestriction) content2.Content;
                     this.CleanupParticle(restriction2.Particle);
                     this.CleanupAttributes(restriction2.Attributes);
                 }
             }
         }
         else
         {
             this.CleanupParticle(complexType.Particle);
             this.CleanupAttributes(complexType.Attributes);
         }
         complexType.LocalElements.Clear();
         complexType.AttributeUses.Clear();
         complexType.SetAttributeWildcard(null);
         complexType.SetContentTypeParticle(XmlSchemaParticle.Empty);
         complexType.ElementDecl = null;
         complexType.HasWildCard = false;
         if (complexType.Redefined != null)
         {
             this.CleanupComplexType(complexType.Redefined as XmlSchemaComplexType);
         }
     }
 }
        private static void CleanupComplexType(XmlSchemaComplexType complexType) {
            if (complexType.ContentModel != null) { //simpleContent or complexContent
                if (complexType.ContentModel is XmlSchemaSimpleContent) {
                    XmlSchemaSimpleContent simpleContent = (XmlSchemaSimpleContent)complexType.ContentModel;
                    if (simpleContent.Content is XmlSchemaSimpleContentExtension) {
                        XmlSchemaSimpleContentExtension simpleExtension = (XmlSchemaSimpleContentExtension)simpleContent.Content;
                        CleanupAttributes(simpleExtension.Attributes);
                    }
                    else { //simpleContent.Content is XmlSchemaSimpleContentRestriction
                        XmlSchemaSimpleContentRestriction simpleRestriction = (XmlSchemaSimpleContentRestriction)simpleContent.Content;
                        CleanupAttributes(simpleRestriction.Attributes);
                    }
                }
                else { // complexType.ContentModel is XmlSchemaComplexContent
                    XmlSchemaComplexContent complexContent = (XmlSchemaComplexContent)complexType.ContentModel;
                    if (complexContent.Content is XmlSchemaComplexContentExtension) {
                        XmlSchemaComplexContentExtension complexExtension = (XmlSchemaComplexContentExtension)complexContent.Content;
                        CleanupParticle(complexExtension.Particle);
                        CleanupAttributes(complexExtension.Attributes);

                    }
                    else { //XmlSchemaComplexContentRestriction
                        XmlSchemaComplexContentRestriction complexRestriction = (XmlSchemaComplexContentRestriction)complexContent.Content;
                        CleanupParticle(complexRestriction.Particle);
                        CleanupAttributes(complexRestriction.Attributes);
                    }
                }
            }
            else { //equals XmlSchemaComplexContent with baseType is anyType
                CleanupParticle(complexType.Particle);
                CleanupAttributes(complexType.Attributes);
            }
            complexType.LocalElements.Clear();
            complexType.AttributeUses.Clear();
            complexType.SetAttributeWildcard(null);
            complexType.SetContentTypeParticle(XmlSchemaParticle.Empty);
            complexType.ElementDecl = null;
        }
Exemple #12
0
        private void CompileLocalAttributes(XmlSchemaComplexType baseType, XmlSchemaComplexType derivedType, XmlSchemaObjectCollection attributes, XmlSchemaAnyAttribute anyAttribute, XmlSchemaDerivationMethod derivedBy) {
            XmlSchemaAnyAttribute baseAttributeWildcard = baseType != null ? baseType.AttributeWildcard : null;       
            foreach (XmlSchemaObject obj in attributes) {
                if (obj is XmlSchemaAttribute) {
                    XmlSchemaAttribute attribute = (XmlSchemaAttribute)obj;
                    if (attribute.Use != XmlSchemaUse.Prohibited) {
                        CompileAttribute(attribute);
                    }
                    if (derivedType.AttributeUses[attribute.QualifiedName] == null) {
                        derivedType.AttributeUses.Add(attribute.QualifiedName, attribute);
                    }
                    else  {
                        SendValidationEvent(Res.Sch_DupAttributeUse, attribute.QualifiedName.ToString(), attribute);
                    }
                }
                else { // is XmlSchemaAttributeGroupRef
                    XmlSchemaAttributeGroupRef attributeGroupRef = (XmlSchemaAttributeGroupRef)obj;
                    XmlSchemaAttributeGroup attributeGroup = (XmlSchemaAttributeGroup)this.schema.AttributeGroups[attributeGroupRef.RefName];
                    if (attributeGroup != null) {
                        CompileAttributeGroup(attributeGroup);
                        foreach (XmlSchemaAttribute attribute in attributeGroup.AttributeUses.Values) {
                            if (derivedType.AttributeUses[attribute.QualifiedName] == null) {
                                derivedType.AttributeUses.Add(attribute.QualifiedName, attribute);
                            }
                            else {
                                SendValidationEvent(Res.Sch_DupAttributeUse, attribute.QualifiedName.ToString(), attributeGroupRef);
                            }
                        }
                        anyAttribute = CompileAnyAttributeIntersection(anyAttribute, attributeGroup.AttributeWildcard);
                    }
                    else {
                        SendValidationEvent(Res.Sch_UndefAttributeGroupRef, attributeGroupRef.RefName.ToString(), attributeGroupRef);
                    }
                }
            }

            // check derivation rules
            if (baseType != null) {
                if (derivedBy == XmlSchemaDerivationMethod.Extension) {
                    derivedType.SetAttributeWildcard(CompileAnyAttributeUnion(anyAttribute, baseAttributeWildcard));
                    foreach(XmlSchemaAttribute attributeBase in baseType.AttributeUses.Values) {
                        XmlSchemaAttribute attribute = (XmlSchemaAttribute)derivedType.AttributeUses[attributeBase.QualifiedName];
                        if (attribute != null) {
                            if (attribute.Use != XmlSchemaUse.Prohibited && attributeBase.Use != XmlSchemaUse.Prohibited) {
                                if (attribute.AttributeType != attributeBase.AttributeType) {
                                    SendValidationEvent(Res.Sch_InvalidAttributeExtension, attribute);
                                }
                            }
                        }
                        else {
                            derivedType.AttributeUses.Add(attributeBase.QualifiedName, attributeBase);
                        }
                    }
                }
                else {  // derivedBy == XmlSchemaDerivationMethod.Restriction
                    // Schema Component Constraint: Derivation Valid (Restriction, Complex)
                    if ((anyAttribute != null) && (baseAttributeWildcard == null || !XmlSchemaAnyAttribute.IsSubset(anyAttribute, baseAttributeWildcard))) {
                        SendValidationEvent(Res.Sch_InvalidAnyAttributeRestriction, derivedType);
                    }
                    else {
                        derivedType.SetAttributeWildcard(anyAttribute); //complete wildcard
                    }

                    // Add form the base
                    foreach(XmlSchemaAttribute attributeBase in baseType.AttributeUses.Values) {
                        XmlSchemaAttribute attribute = (XmlSchemaAttribute)derivedType.AttributeUses[attributeBase.QualifiedName];
                        if (attribute == null) {
                            derivedType.AttributeUses.Add(attributeBase.QualifiedName, attributeBase);
                        } 
                        else {
                            if (attributeBase.Use == XmlSchemaUse.Prohibited && attribute.Use != XmlSchemaUse.Prohibited) {
#if DEBUG
                                string position = string.Empty;
                                if (derivedType.SourceUri != null) {
                                    position = " in " + derivedType.SourceUri + "(" + derivedType.LineNumber + ", " + derivedType.LinePosition + ")";
                                }
                                Debug.WriteLineIf(CompModSwitches.XmlSchema.TraceError, "Invalid complexType attributes restriction" + position);
                                Debug.WriteLineIf(CompModSwitches.XmlSchema.TraceError, "     Base    " + DumpAttributes(baseType.AttributeUses, baseType.AttributeWildcard));
                                Debug.WriteLineIf(CompModSwitches.XmlSchema.TraceError, "     Derived " + DumpAttributes(derivedType.AttributeUses, derivedType.AttributeWildcard));
#endif
                                SendValidationEvent(Res.Sch_AttributeRestrictionProhibited, attribute);
                            } 
                            else if (attribute.Use == XmlSchemaUse.Prohibited) {
                                continue;
                            } 
                            else if (attributeBase.AttributeType == null || attribute.AttributeType == null || !XmlSchemaType.IsDerivedFrom(attribute.AttributeType, attributeBase.AttributeType, XmlSchemaDerivationMethod.Empty)) {
                                SendValidationEvent(Res.Sch_AttributeRestrictionInvalid, attribute);
                            }
                        }
                    }

                    // Check additional ones are valid restriction of base's wildcard
                    foreach(XmlSchemaAttribute attribute in derivedType.AttributeUses.Values) {
                        XmlSchemaAttribute attributeBase = (XmlSchemaAttribute)baseType.AttributeUses[attribute.QualifiedName];
                        if (attributeBase != null) {
                            continue;
                        }
                        if (baseAttributeWildcard == null || !baseAttributeWildcard.Allows(attribute.QualifiedName)) {
#if DEBUG
                            string position = string.Empty;
                            if (derivedType.SourceUri != null) {
                                position = " in " + derivedType.SourceUri + "(" + derivedType.LineNumber + ", " + derivedType.LinePosition + ")";
                            }
                            Debug.WriteLineIf(CompModSwitches.XmlSchema.TraceError, "Invalid complexType attributes restriction" + position);
                            Debug.WriteLineIf(CompModSwitches.XmlSchema.TraceError, "     Base    " + DumpAttributes(baseType.AttributeUses, baseType.AttributeWildcard));
                            Debug.WriteLineIf(CompModSwitches.XmlSchema.TraceError, "     Derived " + DumpAttributes(derivedType.AttributeUses, derivedType.AttributeWildcard));
#endif
                            SendValidationEvent(Res.Sch_AttributeRestrictionInvalidFromWildcard, attribute);
                        }
                    }
                }
            } 
            else {
                derivedType.SetAttributeWildcard(anyAttribute);
            }
       }
 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;
 }