Inheritance: XmlSchemaContentModel
Example #1
0
        XObject[] CreateProtoComplexType(XmlSchemaComplexType complexType) {
            if (complexType.ContentModel != null) {
                if ((complexType.ContentModel as XmlSchemaSimpleContent) != null) {
                    return CreateProtoSimpleContent((complexType.ContentModel as XmlSchemaSimpleContent), complexType.BaseXmlSchemaType).ToArray();
                } else if ((complexType.ContentModel as XmlSchemaComplexContent) != null) {
                    return CreateProtoComplexContent((complexType.ContentModel as XmlSchemaComplexContent), complexType.BaseXmlSchemaType).ToArray();
                } else {
                    throw new Exception("not implemented");
                }
            } else {
                var complexContentExt = new XmlSchemaComplexContentExtension();
                if (complexType.BaseXmlSchemaType != null) {
                    complexContentExt.BaseTypeName = complexType.BaseXmlSchemaType.QualifiedName;
                } else {
                    complexContentExt.BaseTypeName = null;
                }

                if (complexType.Attributes != null) {
                    foreach (var i in complexType.Attributes) {
                        complexContentExt.Attributes.Add(i);
                    }
                }
                complexContentExt.Particle = complexType.Particle;
                var complexContent = new XmlSchemaComplexContent();
                complexContent.Content = complexContentExt;
                return CreateProtoComplexContent(complexContent, complexType.BaseXmlSchemaType).ToArray();
            }
        }
Example #2
0
        private Particle PopulateParticle(ComplexType ct)
        {
            if (ct.ContentModel == null)
            {
                if (ct.Particle == null)
                {
                    ct.Particle = CreateSequence();
                }
                return(ct.Particle);
            }
            ComplexModel cm = ct.ContentModel as ComplexModel;

            if (cm != null)
            {
                ComplexExt ce = cm.Content as ComplexExt;
                if (ce != null)
                {
                    if (ce.Particle == null)
                    {
                        ce.Particle = CreateSequence();
                    }
                    return(ce.Particle);
                }
                ComplexRst cr = cm.Content as ComplexRst;
                if (cr != null)
                {
                    if (cr.Particle == null)
                    {
                        cr.Particle = CreateSequence();
                    }
                    return(cr.Particle);
                }
            }
            throw Error(ct, "Schema inference internal error. The complexType should have been converted to have a complex content.");
        }
Example #3
0
        private void MarkAsMixed(ComplexType ct)
        {
            ComplexModel cm = ct.ContentModel as ComplexModel;

            if (cm != null)
            {
                cm.IsMixed = true;
            }
            else
            {
                ct.IsMixed = true;
            }
        }
Example #4
0
        private void InferAsEmptyElement(Element el, string ns,
                                         bool isNew)
        {
            ComplexType ct = el.SchemaType as ComplexType;

            if (ct != null)
            {
                SimpleModel sm =
                    ct.ContentModel as SimpleModel;
                if (sm != null)
                {
                    ToEmptiableSimpleContent(sm, isNew);
                    return;
                }

                ComplexModel cm = ct.ContentModel
                                  as ComplexModel;
                if (cm != null)
                {
                    ToEmptiableComplexContent(cm, isNew);
                    return;
                }

                if (ct.Particle != null)
                {
                    ct.Particle.MinOccurs = 0;
                }
                return;
            }
            SimpleType st = el.SchemaType as SimpleType;

            if (st != null)
            {
                st = MakeBaseTypeAsEmptiable(st);
                switch (st.QualifiedName.Namespace)
                {
                case XmlSchema.Namespace:
                case XdtNamespace:
                    el.SchemaTypeName = st.QualifiedName;
                    break;

                default:
                    el.SchemaType = st;
                    break;
                }
            }
        }
Example #5
0
        private SOMList GetAttributes(ComplexType ct)
        {
            if (ct.ContentModel == null)
            {
                return(ct.Attributes);
            }

            SimpleModel sc = ct.ContentModel as SimpleModel;

            if (sc != null)
            {
                SimpleExt sce = sc.Content as SimpleExt;
                if (sce != null)
                {
                    return(sce.Attributes);
                }
                SimpleRst scr = sc.Content as SimpleRst;
                if (scr != null)
                {
                    return(scr.Attributes);
                }
                else
                {
                    throw Error(sc, "Invalid simple content model.");
                }
            }
            ComplexModel cc = ct.ContentModel as ComplexModel;

            if (cc != null)
            {
                ComplexExt cce = cc.Content as ComplexExt;
                if (cce != null)
                {
                    return(cce.Attributes);
                }
                ComplexRst ccr = cc.Content as ComplexRst;
                if (ccr != null)
                {
                    return(ccr.Attributes);
                }
                else
                {
                    throw Error(cc, "Invalid simple content model.");
                }
            }
            throw Error(cc, "Invalid complexType. Should not happen.");
        }
Example #6
0
        private void ToEmptiableComplexContent(
            ComplexModel cm, bool isNew)
        {
            ComplexExt ce = cm.Content
                            as ComplexExt;

            if (ce != null)
            {
                if (ce.Particle != null)
                {
                    ce.Particle.MinOccurs = 0;
                }
                else if (ce.BaseTypeName != null &&
                         ce.BaseTypeName != QName.Empty &&
                         ce.BaseTypeName != QNameAnyType)
                {
                    throw Error(ce, "Complex type content extension has a reference to an external component that is not supported.");
                }
            }
            else
            {
                ComplexRst cr = cm.Content
                                as ComplexRst;
                if (cr == null)
                {
                    throw Error(cm, "Invalid complex content model was passed.");
                }
                if (cr.Particle != null)
                {
                    cr.Particle.MinOccurs = 0;
                }
                else if (cr.BaseTypeName != null &&
                         cr.BaseTypeName != QName.Empty &&
                         cr.BaseTypeName != QNameAnyType)
                {
                    throw Error(cr, "Complex type content extension has a reference to an external component that is not supported.");
                }
            }
        }
        static void AddAppSequenceType(DiscoveryVersion discoveryVersion, XmlSchema schema)
        {
            //<xs:complexType name="AppSequenceType" >
            XmlSchemaComplexType appSequenceType = new XmlSchemaComplexType();
            appSequenceType.Name = ProtocolStrings.SchemaNames.AppSequenceType;

            // <xs:complexContent>
            XmlSchemaComplexContent complexContent = new XmlSchemaComplexContent();
            appSequenceType.ContentModel = complexContent;

            // <xs:restriction base="xs:anyType" >
            XmlSchemaComplexContentRestriction contentRestriction = new XmlSchemaComplexContentRestriction();
            complexContent.Content = contentRestriction;
            contentRestriction.BaseTypeName = discoveryVersion.Implementation.QualifiedNames.AnyType;

            // <xs:attribute name="InstanceId" type="xs:unsignedInt" use="required" />
            XmlSchemaAttribute instanceId = new XmlSchemaAttribute();
            instanceId.Name = ProtocolStrings.SchemaNames.AppSequenceInstanceId;
            instanceId.SchemaTypeName = discoveryVersion.Implementation.QualifiedNames.UnsignedIntType;
            instanceId.Use = XmlSchemaUse.Required;

            // <xs:attribute name="SequenceId" type="xs:anyURI" />
            XmlSchemaAttribute sequenceId = new XmlSchemaAttribute();
            sequenceId.Name = ProtocolStrings.SchemaNames.AppSequenceSequenceId;
            sequenceId.SchemaTypeName = discoveryVersion.Implementation.QualifiedNames.AnyUriType;

            // <xs:attribute name="MessageNumber" type="xs:unsignedInt" use="required" />
            XmlSchemaAttribute messageNumber = new XmlSchemaAttribute();
            messageNumber.Name = ProtocolStrings.SchemaNames.AppSequenceMessageNumber;
            messageNumber.SchemaTypeName = discoveryVersion.Implementation.QualifiedNames.UnsignedIntType;
            messageNumber.Use = XmlSchemaUse.Required;

            // <xs:anyAttribute namespace="##other" processContents="lax" />
            XmlSchemaAnyAttribute anyAttribue = new XmlSchemaAnyAttribute();
            anyAttribue.Namespace = "##other";
            anyAttribue.ProcessContents = XmlSchemaContentProcessing.Lax;

            contentRestriction.Attributes.Add(instanceId);
            contentRestriction.Attributes.Add(sequenceId);
            contentRestriction.Attributes.Add(messageNumber);
            contentRestriction.AnyAttribute = anyAttribue;

            schema.Items.Add(appSequenceType);
        }
 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);
     }
 }
 internal XmlSchemaObject Clone(XmlSchema parentSchema)
 {
     XmlSchemaComplexType type = (XmlSchemaComplexType) base.MemberwiseClone();
     if (type.ContentModel != null)
     {
         XmlSchemaSimpleContent contentModel = type.ContentModel as XmlSchemaSimpleContent;
         if (contentModel != null)
         {
             XmlSchemaSimpleContent content2 = (XmlSchemaSimpleContent) contentModel.Clone();
             XmlSchemaSimpleContentExtension content = contentModel.Content as XmlSchemaSimpleContentExtension;
             if (content != null)
             {
                 XmlSchemaSimpleContentExtension extension2 = (XmlSchemaSimpleContentExtension) content.Clone();
                 extension2.BaseTypeName = content.BaseTypeName.Clone();
                 extension2.SetAttributes(CloneAttributes(content.Attributes));
                 content2.Content = extension2;
             }
             else
             {
                 XmlSchemaSimpleContentRestriction restriction = (XmlSchemaSimpleContentRestriction) contentModel.Content;
                 XmlSchemaSimpleContentRestriction restriction2 = (XmlSchemaSimpleContentRestriction) restriction.Clone();
                 restriction2.BaseTypeName = restriction.BaseTypeName.Clone();
                 restriction2.SetAttributes(CloneAttributes(restriction.Attributes));
                 content2.Content = restriction2;
             }
             type.ContentModel = content2;
         }
         else
         {
             XmlSchemaComplexContent content3 = (XmlSchemaComplexContent) type.ContentModel;
             XmlSchemaComplexContent content4 = (XmlSchemaComplexContent) content3.Clone();
             XmlSchemaComplexContentExtension extension3 = content3.Content as XmlSchemaComplexContentExtension;
             if (extension3 != null)
             {
                 XmlSchemaComplexContentExtension extension4 = (XmlSchemaComplexContentExtension) extension3.Clone();
                 extension4.BaseTypeName = extension3.BaseTypeName.Clone();
                 extension4.SetAttributes(CloneAttributes(extension3.Attributes));
                 if (HasParticleRef(extension3.Particle, parentSchema))
                 {
                     extension4.Particle = CloneParticle(extension3.Particle, parentSchema);
                 }
                 content4.Content = extension4;
             }
             else
             {
                 XmlSchemaComplexContentRestriction restriction3 = content3.Content as XmlSchemaComplexContentRestriction;
                 XmlSchemaComplexContentRestriction restriction4 = (XmlSchemaComplexContentRestriction) restriction3.Clone();
                 restriction4.BaseTypeName = restriction3.BaseTypeName.Clone();
                 restriction4.SetAttributes(CloneAttributes(restriction3.Attributes));
                 if (HasParticleRef(restriction4.Particle, parentSchema))
                 {
                     restriction4.Particle = CloneParticle(restriction4.Particle, parentSchema);
                 }
                 content4.Content = restriction4;
             }
             type.ContentModel = content4;
         }
     }
     else
     {
         if (HasParticleRef(type.Particle, parentSchema))
         {
             type.Particle = CloneParticle(type.Particle, parentSchema);
         }
         type.SetAttributes(CloneAttributes(type.Attributes));
     }
     type.ClearCompiledState();
     return type;
 }
Example #10
0
        private void BuildComplexContent(XmlSchemaComplexContent complexContent, CodeTypeDeclaration codeType)
        {
            // If this is an extension type
            if (complexContent.Content.GetType() == typeof(XmlSchemaComplexContentExtension))
            {
                XmlSchemaComplexContentExtension extension = (XmlSchemaComplexContentExtension)complexContent.Content;

                // Add Attributes
                foreach (XmlSchemaAttribute attribute in extension.Attributes)
                {
                    WriteAttributeField(attribute, codeType, attribute.DefaultValue);
                }

                // (Mod:11-26-08) If the particle is null return after adding attributes. The derived type is does not change the base type.
                if (extension.Particle == null)
                    return;

                // If extension has sequence particles
                if (extension.Particle.GetType() == typeof(XmlSchemaSequence))
                {
                    ProcessSequence((XmlSchemaSequence)extension.Particle, codeType);
                }
                else if (extension.Particle.GetType() == typeof(XmlSchemaChoice))
                {
                    ProcessChoice((XmlSchemaChoice)extension.Particle, codeType);
                }
                else if (extension.Particle.GetType() == typeof(XmlSchemaAll))
                {
                    ProcessAll((XmlSchemaAll)extension.Particle, codeType);
                }

                // Add anyAttribute if not null
                if (extension.AnyAttribute != null)
                    WriteAnyAttribute(extension.AnyAttribute, codeType);
            }
            // Else if this is a type restriction
            else if (complexContent.Content.GetType() == typeof(XmlSchemaComplexContentRestriction))
            {
                // need to add code to handle complex type restrictions here
                XmlSchemaComplexContentRestriction restriction = (XmlSchemaComplexContentRestriction)complexContent.Content;

                // (Mod:11-26-08) If the particle is null return after adding attributes. The derived type is does not change the base type.
                if (restriction.Particle == null)
                    return;
            }
        }
 void Write41_XmlSchemaComplexContent(XmlSchemaComplexContent o) {
     if ((object)o == null) return;
     WriteStartElement("complexContent");
     
     WriteAttribute(@"id", @"", ((System.String)o.@Id));
     WriteAttribute(@"mixed", @"", XmlConvert.ToString((System.Boolean)((System.Boolean)o.@IsMixed)));
     WriteAttributes((XmlAttribute[])o.@UnhandledAttributes, o);
     Write5_XmlSchemaAnnotation((XmlSchemaAnnotation)o.@Annotation);
     if (o.@Content is XmlSchemaComplexContentRestriction) {
         Write56_XmlSchemaComplexContentRestriction((XmlSchemaComplexContentRestriction)o.@Content);
     }
     else if (o.@Content is XmlSchemaComplexContentExtension) {
         Write42_XmlSchemaComplexContentExtension((XmlSchemaComplexContentExtension)o.@Content);
     }
     WriteEndElement();
 }
		XmlSchemaAttribute FindAttribute(XmlSchemaComplexContent complexContent, string name)
		{
			XmlSchemaComplexContentExtension extension = complexContent.Content as XmlSchemaComplexContentExtension;
			XmlSchemaComplexContentRestriction restriction = complexContent.Content as XmlSchemaComplexContentRestriction;
			
			if (extension != null) {
				return FindAttribute(extension, name);
			} else if (restriction != null) {
				return FindAttribute(restriction, name);
			}
			return null;
		}
Example #13
0
        private string SchemaSearching(XmlSchema xmlSchema, string inputParamType)
        {
            string       returnval = null;
            XmlGenerator xmlGen    = new XmlGenerator();

            foreach (object item in xmlSchema.Items)
            {
                System.Xml.Schema.XmlSchemaElement schemaElement = item as System.Xml.Schema.XmlSchemaElement;
                if (schemaElement != null)
                {
                    if (schemaElement.Name == inputParamType)
                    {
                        returnval = xmlGen.GenerateXmlString(schemaElement, xmlSchema);
                        break;//The parameter was found no need to go through rest of elements
                    }
                }
                else
                { //This is a complex Type
                    System.Xml.Schema.XmlSchemaComplexType complexType = item as System.Xml.Schema.XmlSchemaComplexType;
                    if (complexType != null)
                    {
                        if (complexType.Name == inputParamType)
                        {
                            Logger.Text += "Complex Type Name : " + complexType.Name + "\r\n";
                            System.Xml.Schema.XmlSchemaParticle particle  = complexType.Particle;
                            System.Xml.Schema.XmlSchemaSequence sequence  = particle as System.Xml.Schema.XmlSchemaSequence;
                            System.Xml.Schema.XmlSchemaAll      schemaall = particle as System.Xml.Schema.XmlSchemaAll;
                            if (sequence != null)
                            {
                                foreach (System.Xml.Schema.XmlSchemaElement childElement in sequence.Items)
                                {
                                    string parameterName = childElement.Name;
                                    string parameterType = childElement.SchemaTypeName.Name;
                                    returnval = '<' + complexType.Name + '>' + xmlGen.GenerateXmlString(childElement, xmlSchema) + "</" + complexType.Name + '>';
                                }
                            }
                            else
                            {
                                if (schemaall != null)
                                {
                                    returnval = '<' + complexType.Name + '>' + xmlGen.GenerateXmlString(schemaall, xmlSchema) + "</" + complexType.Name + '>';
                                }
                                else
                                {
                                    System.Xml.Schema.XmlSchemaComplexContent cmplxContent = null;
                                    if (cmplxContent != null)
                                    {
                                        returnval = '<' + complexType.Name + '>' + xmlGen.GenerateXmlString(cmplxContent, xmlSchema) + "</" + complexType.Name + '>';;
                                    }
                                }
                            }
                            break;  //The parameter was found no need to go through rest of elements
                        }
                    }
                    else
                    {   //Nothing to do?
                        //System.Xml.Schema.XmlSchemaSimpleType simpleType = item as System.Xml.Schema.XmlSchemaSimpleType;
                    }
                }
            }
            return(returnval);
        }
		void GetChildElementCompletionData (XmlCompletionDataList data, XmlSchemaComplexContent complexContent, string prefix)
		{
			var extension = complexContent.Content as XmlSchemaComplexContentExtension;
			if (extension != null) {
				GetChildElementCompletionData (data, extension, prefix);
				return;
			}
			var restriction = complexContent.Content as XmlSchemaComplexContentRestriction;
			if (restriction != null) {
				GetChildElementCompletionData (data, restriction, prefix);
				return;
			}
		}
Example #15
0
                /// <summary>
                ///     Handle derivation by extension.
                ///     If type is null, it'll create a new complexType
                ///     with an XmlAny node in its sequence child node.
                /// </summary>
                public XmlSchemaType WriteComplexSchemaType (Type type)
                {
                        //
                        // Recursively generate schema for all parent types
                        //
                        if (type != null && type.BaseType == typeof (object))
                                return WriteSchemaType (type);

                        XmlSchemaComplexType complexType = new XmlSchemaComplexType ();
                        XmlSchemaSequence sequence;
                        XmlSchemaComplexContentExtension extension = new XmlSchemaComplexContentExtension ();
                        XmlSchemaComplexContent content = new XmlSchemaComplexContent ();

                        complexType.ContentModel = content;
                        content.Content = extension;

                        XmlSchemaType baseSchemaType = WriteSchemaType (type.BaseType);

                        complexType.Name = type.Name;

                        FieldInfo [] fields = type.GetFields (flags);
                        PropertyInfo [] properties = type.GetProperties (flags);

                        try {
                                sequence = PopulateSequence (fields, properties);
                                if (attributes != null) {
                                        foreach (object o in attributes) {
                                                MemberInfo member = (MemberInfo) o;
                                                Type attribute_type = (Type) attributes [o];

                                                complexType.Attributes.Add (WriteSchemaAttribute (member, attribute_type));
                                        }
                                }
                        } catch (ArgumentException e) {
                                throw new ArgumentException (String.Format ("There is an error in '{0}'\n\t{1}", type.Name, e.Message));
                        }

                        extension.BaseTypeName = new XmlQualifiedName (baseSchemaType.Name);
                        extension.Particle = sequence;

                        generatedSchemaTypes.Add (type.FullName, complexType);
                        return complexType;
                }
Example #16
0
		XmlQualifiedName ExportArraySchema (XmlTypeMapping map, string defaultNamespace)
		{
			ListMap lmap = (ListMap) map.ObjectMap;

			if (encodedFormat)
			{
				string name, ns, schemaNs;
				lmap.GetArrayType (-1, out name, out ns);				
				if (ns == XmlSchema.Namespace) schemaNs = defaultNamespace;
				else schemaNs = ns;

				if (IsMapExported (map)) return new XmlQualifiedName (lmap.GetSchemaArrayName (), schemaNs);
				SetMapExported (map);

				XmlSchema schema = GetSchema (schemaNs);
				XmlSchemaComplexType stype = new XmlSchemaComplexType ();
				stype.Name = lmap.GetSchemaArrayName ();
				schema.Items.Add (stype);
				
				XmlSchemaComplexContent content = new XmlSchemaComplexContent();
				content.IsMixed = false;
				stype.ContentModel = content;
				
				XmlSchemaComplexContentRestriction rest = new XmlSchemaComplexContentRestriction ();
				content.Content = rest;
				rest.BaseTypeName = new XmlQualifiedName ("Array", XmlSerializer.EncodingNamespace);
				XmlSchemaAttribute at = new XmlSchemaAttribute ();
				rest.Attributes.Add (at);
				at.RefName = new XmlQualifiedName ("arrayType", XmlSerializer.EncodingNamespace);
				
				XmlAttribute arrayType = Document.CreateAttribute ("arrayType", XmlSerializer.WsdlNamespace);
				arrayType.Value = ns + (ns != "" ? ":" : "") + name;
				at.UnhandledAttributes = new XmlAttribute [] { arrayType };
				ImportNamespace (schema, XmlSerializer.WsdlNamespace);
			
				XmlTypeMapElementInfo einfo = (XmlTypeMapElementInfo) lmap.ItemInfo[0];
				if (einfo.MappedType != null)
				{
					switch (einfo.TypeData.SchemaType)
					{
						case SchemaTypes.Enum:
							ExportEnumSchema (einfo.MappedType);
							break;
						case SchemaTypes.Array: 
							ExportArraySchema (einfo.MappedType, schemaNs); 
							break;
						case SchemaTypes.Class:
							ExportClassSchema (einfo.MappedType);
							break;
					}
				}
				
				return new XmlQualifiedName (lmap.GetSchemaArrayName (), schemaNs);
			}
			else
			{
				if (IsMapExported (map)) return new XmlQualifiedName (map.XmlType, map.XmlTypeNamespace);
				
				SetMapExported (map);
				XmlSchema schema = GetSchema (map.XmlTypeNamespace);
				XmlSchemaComplexType stype = new XmlSchemaComplexType ();
				stype.Name = map.ElementName;
				schema.Items.Add (stype);

				XmlSchemaParticle spart = GetSchemaArrayElement (schema, lmap.ItemInfo);
				if (spart is XmlSchemaChoice)
					stype.Particle = spart;
				else
				{
					XmlSchemaSequence seq = new XmlSchemaSequence ();
					seq.Items.Add (spart);
					stype.Particle = seq;
				}
					
				return new XmlQualifiedName (map.XmlType, map.XmlTypeNamespace);
			}
		}
		XmlSchemaAttribute FindAttribute (XmlSchemaComplexContent complexContent, string name)
		{
			var extension = complexContent.Content as XmlSchemaComplexContentExtension;
			if (extension != null)
				return FindAttribute (extension, name);
			
			var restriction = complexContent.Content as XmlSchemaComplexContentRestriction;
			if (restriction != null)
				return FindAttribute (restriction, name);
			
			return null;
		}		
Example #18
0
		void ExportClassSchema (XmlTypeMapping map)
		{
			if (IsMapExported (map)) return;
			SetMapExported (map);
			
			if (map.TypeData.Type == typeof(object))
			{
				foreach (XmlTypeMapping dmap in map.DerivedTypes)
					if (dmap.TypeData.SchemaType == SchemaTypes.Class) ExportClassSchema (dmap);
				return;
			}

			XmlSchema schema = GetSchema (map.XmlTypeNamespace);
			XmlSchemaComplexType stype = new XmlSchemaComplexType ();
			stype.Name = map.XmlType;
			schema.Items.Add (stype);

			ClassMap cmap = (ClassMap)map.ObjectMap;

			if (cmap.HasSimpleContent)
			{
				XmlSchemaSimpleContent simple = new XmlSchemaSimpleContent ();
				stype.ContentModel = simple;
				XmlSchemaSimpleContentExtension ext = new XmlSchemaSimpleContentExtension ();
				simple.Content = ext;
				XmlSchemaSequence particle;
				XmlSchemaAnyAttribute anyAttribute;
				ExportMembersMapSchema (schema, cmap, map.BaseMap, ext.Attributes, out particle, out anyAttribute);
				ext.AnyAttribute = anyAttribute;
				if (map.BaseMap == null)
					ext.BaseTypeName = cmap.SimpleContentBaseType;
				else {
					ext.BaseTypeName = new XmlQualifiedName (map.BaseMap.XmlType, map.BaseMap.XmlTypeNamespace);
					ImportNamespace (schema, map.BaseMap.XmlTypeNamespace);
					ExportClassSchema (map.BaseMap);
				}
			}
			else if (map.BaseMap != null && map.BaseMap.IncludeInSchema)
			{
				XmlSchemaComplexContent cstype = new XmlSchemaComplexContent ();
				XmlSchemaComplexContentExtension ext = new XmlSchemaComplexContentExtension ();
				ext.BaseTypeName = new XmlQualifiedName (map.BaseMap.XmlType, map.BaseMap.XmlTypeNamespace);
				cstype.Content = ext;
				stype.ContentModel = cstype;

				XmlSchemaSequence particle;
				XmlSchemaAnyAttribute anyAttribute;
				ExportMembersMapSchema (schema, cmap, map.BaseMap, ext.Attributes, out particle, out anyAttribute);
				ext.Particle = particle;
				ext.AnyAttribute = anyAttribute;
				stype.IsMixed = HasMixedContent (map);
				cstype.IsMixed = BaseHasMixedContent (map);

				ImportNamespace (schema, map.BaseMap.XmlTypeNamespace);
				ExportClassSchema (map.BaseMap);
			}
			else
			{
				XmlSchemaSequence particle;
				XmlSchemaAnyAttribute anyAttribute;
				ExportMembersMapSchema (schema, cmap, map.BaseMap, stype.Attributes, out particle, out anyAttribute);
				stype.Particle = particle;
				stype.AnyAttribute = anyAttribute;
				stype.IsMixed = cmap.XmlTextCollector != null;
			}
			
			foreach (XmlTypeMapping dmap in map.DerivedTypes)
				if (dmap.TypeData.SchemaType == SchemaTypes.Class) ExportClassSchema (dmap);
		}
Example #19
0
        /// <summary>
        /// Creates the an xml schema for a complex type. This method automatically takes care of
        /// any base classes that must be added.
        /// <para />
        /// This method already adds the <see cref="XmlSchemaComplexType" /> to the <see cref="XmlSchemaSet" />.
        /// </summary>
        /// <param name="type">The type to create the complex schema for.</param>
        /// <param name="schema">The schema.</param>
        /// <param name="schemaSet">The schema set.</param>
        /// <param name="serializationManager">The serialization manager.</param>
        /// <param name="generateFlatSchema">A value indicating whether the schema should be generated as flat schema.</param>
        /// <returns>The complex schema for the specified type.</returns>
        private static XmlSchemaComplexType CreateSchemaComplexType(Type type, XmlSchema schema, XmlSchemaSet schemaSet, ISerializationManager serializationManager, bool generateFlatSchema)
        {
            // Determine name, which is complex in generic types
            string typeName = GetTypeNameForSchema(type);

            // First, add the type, otherwise we might get into a stackoverflow when using generic base types
            // <xs:complexType>
            var modelBaseType = new XmlSchemaComplexType();
            modelBaseType.Name = typeName;
            modelBaseType.IsMixed = false;

            schema.Items.Add(modelBaseType);

            var propertiesSequence = GetPropertiesSequence(type, schema, schemaSet, serializationManager);

            // If flat, don't generate base classes, just the type itself
            if (generateFlatSchema)
            {
                modelBaseType.Particle = propertiesSequence;
                return modelBaseType;
            }

            if (type.IsGenericType)
            {
                var genericComplexType = new XmlSchemaComplexType();
                genericComplexType.Name = typeName;

                // <xs:annotation>
                var annotation = new XmlSchemaAnnotation();

                // <xs:appinfo>
                var appInfo = new XmlSchemaAppInfo();

                //<GenericType xmlns="http://schemas.microsoft.com/2003/10/Serialization/" Name="DataContractBaseOf{0}{#}" Namespace="http://schemas.datacontract.org/2004/07/STC">
                //  <GenericParameter Name="ProfileDateRange2" Namespace="http://schemas.datacontract.org/2004/07/STC.Meter.ProfileData"/>
                //</GenericType>
                var genericTypeElement = new XElement("GenericType");
                genericTypeElement.Add(new XAttribute("Name", string.Format("{0}Of{{0}}{{#}}", typeName)));
                genericTypeElement.Add(new XAttribute("Namespace", GetTypeNamespaceForSchema(type)));

                foreach (var genericArgument in type.GetGenericArgumentsEx())
                {
                    var genericArgumentQualifiedName = AddTypeToSchemaSet(genericArgument, schemaSet, serializationManager);
                    var genericArgumentElement = new XElement("GenericParameter");
                    genericArgumentElement.Add(new XAttribute("Name", genericArgumentQualifiedName.Name));
                    genericArgumentElement.Add(new XAttribute("Namespace", genericArgumentQualifiedName.Namespace));
                    genericTypeElement.Add(genericArgumentElement);
                }

                var conversionDoc = new XmlDocument();
                appInfo.Markup = new XmlNode[] { conversionDoc.CreateTextNode(genericTypeElement.ToString()) };

                annotation.Items.Add(appInfo);
            }

            var baseTypeQualifiedName = AddTypeToSchemaSet(type.BaseType, schemaSet, serializationManager);
            if (baseTypeQualifiedName != null)
            {
                // <xs:extensions base="address">
                var complexContentExtension = new XmlSchemaComplexContentExtension();
                complexContentExtension.BaseTypeName = baseTypeQualifiedName;
                complexContentExtension.Particle = propertiesSequence;

                // <xs:complexContent>
                var complexContent = new XmlSchemaComplexContent();
                complexContent.Content = complexContentExtension;

                modelBaseType.ContentModel = complexContent;
            }

            return modelBaseType;
        }
        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);
        }
Example #21
0
        void WriteComplexContent(XmlTextWriter xtw, string ns, XmlSchemaComplexContent content)
        {
            XmlQualifiedName qname;

            XmlSchemaComplexContentExtension ext = content.Content as XmlSchemaComplexContentExtension;
            if (ext != null) qname = ext.BaseTypeName;
            else {
                XmlSchemaComplexContentRestriction rest = (XmlSchemaComplexContentRestriction)content.Content;
                qname = rest.BaseTypeName;
                if (qname == arrayType) {
                    ParseArrayType(rest, out qname);
                    XmlSchemaElement elem = new XmlSchemaElement();
                    elem.Name = "Item";
                    elem.SchemaTypeName = qname;

                    xtw.WriteAttributeString("arrayType", SoapEncodingNamespace, qname.Name + "[2]");
                    WriteContentItem(xtw, ns, elem, true);
                    return;
                }
            }

            // Add base map members to this map
            XmlSchemaComplexType ctype = FindComplexTyype(qname);
            WriteComplexTypeAttributes(xtw, ctype);

            if (ext != null) {
                // Add the members of this map
                WriteAttributes(xtw, ext.Attributes, ext.AnyAttribute);
                if (ext.Particle != null)
                    WriteParticleComplexContent(xtw, ns, ext.Particle);
            }

            WriteComplexTypeElements(xtw, ns, ctype);
        }
Example #22
0
        //<complexContent
        //  id = ID
        //  mixed = boolean
        //  {any attributes with non-schema namespace . . .}>
        //  Content: (annotation?, (restriction | extension))
        //</complexContent>
        internal static XmlSchemaComplexContent Read(XmlSchemaReader reader, ValidationEventHandler h)
        {
            XmlSchemaComplexContent complex = new XmlSchemaComplexContent();

            reader.MoveToElement();

            if (reader.NamespaceURI != XmlSchema.Namespace || reader.LocalName != xmlname)
            {
                error(h, "Should not happen :1: XmlSchemaComplexContent.Read, name=" + reader.Name, null);
                reader.Skip();
                return(null);
            }

            complex.LineNumber   = reader.LineNumber;
            complex.LinePosition = reader.LinePosition;
            complex.SourceUri    = reader.BaseURI;

            while (reader.MoveToNextAttribute())
            {
                if (reader.Name == "id")
                {
                    complex.Id = reader.Value;
                }
                else if (reader.Name == "mixed")
                {
                    Exception innerex;
                    complex.isMixed = XmlSchemaUtil.ReadBoolAttribute(reader, out innerex);
                    if (innerex != null)
                    {
                        error(h, reader.Value + " is an invalid value for mixed", innerex);
                    }
                }
                else if ((reader.NamespaceURI == "" && reader.Name != "xmlns") || reader.NamespaceURI == XmlSchema.Namespace)
                {
                    error(h, reader.Name + " is not a valid attribute for complexContent", null);
                }
                else
                {
                    XmlSchemaUtil.ReadUnhandledAttribute(reader, complex);
                }
            }

            reader.MoveToElement();
            if (reader.IsEmptyElement)
            {
                return(complex);
            }
            //Content: (annotation?, (restriction | extension))
            int level = 1;

            while (reader.ReadNextElement())
            {
                if (reader.NodeType == XmlNodeType.EndElement)
                {
                    if (reader.LocalName != xmlname)
                    {
                        error(h, "Should not happen :2: XmlSchemaComplexContent.Read, name=" + reader.Name, null);
                    }
                    break;
                }
                if (level <= 1 && reader.LocalName == "annotation")
                {
                    level = 2; //Only one annotation
                    XmlSchemaAnnotation annotation = XmlSchemaAnnotation.Read(reader, h);
                    if (annotation != null)
                    {
                        complex.Annotation = annotation;
                    }
                    continue;
                }
                if (level <= 2)
                {
                    if (reader.LocalName == "restriction")
                    {
                        level = 3;
                        XmlSchemaComplexContentRestriction restriction = XmlSchemaComplexContentRestriction.Read(reader, h);
                        if (restriction != null)
                        {
                            complex.content = restriction;
                        }
                        continue;
                    }
                    if (reader.LocalName == "extension")
                    {
                        level = 3;
                        XmlSchemaComplexContentExtension extension = XmlSchemaComplexContentExtension.Read(reader, h);
                        if (extension != null)
                        {
                            complex.content = extension;
                        }
                        continue;
                    }
                }
                reader.RaiseInvalidElementError();
            }
            return(complex);
        }
Example #23
0
		private void ToEmptiableComplexContent (
			ComplexModel cm, bool isNew)
		{
			ComplexExt ce = cm.Content
				as ComplexExt;
			if (ce != null) {
				if (ce.Particle != null)
					ce.Particle.MinOccurs = 0;
				else if (ce.BaseTypeName != null &&
					ce.BaseTypeName != QName.Empty &&
					ce.BaseTypeName != QNameAnyType)
					throw Error (ce, "Complex type content extension has a reference to an external component that is not supported.");
			}
			else {
				ComplexRst cr = cm.Content
					as ComplexRst;
				if (cr == null)
					throw Error (cm, "Invalid complex content model was passed.");
				if (cr.Particle != null)
					cr.Particle.MinOccurs = 0;
				else if (cr.BaseTypeName != null &&
					cr.BaseTypeName != QName.Empty &&
					cr.BaseTypeName != QNameAnyType)
					throw Error (cr, "Complex type content extension has a reference to an external component that is not supported.");
			}
		}
        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);
        }
		XmlCompletionItemCollection GetChildElementCompletion(XmlSchemaComplexContent complexContent, string prefix)
		{
			XmlSchemaComplexContentExtension extension = complexContent.Content as XmlSchemaComplexContentExtension;
			if (extension != null) {
				return GetChildElementCompletion(extension, prefix);
			} else {
				XmlSchemaComplexContentRestriction restriction = complexContent.Content as XmlSchemaComplexContentRestriction;
				if (restriction != null) {
					return GetChildElementCompletion(restriction, prefix);
				}
			}
			return new XmlCompletionItemCollection();
		}
Example #26
0
 private void SetContainer(State state, object container) {
     switch (state) {
         case State.Root:
             break;
         case State.Schema:
             break;
         case State.Annotation:
             this.annotation = (XmlSchemaAnnotation)container;
             break;
         case State.Include:
             this.include = (XmlSchemaInclude)container;
             break;
         case State.Import:
             this.import = (XmlSchemaImport)container;
             break;
         case State.Element:
             this.element = (XmlSchemaElement)container;
             break;
         case State.Attribute:
             this.attribute = (XmlSchemaAttribute)container;
             break;
         case State.AttributeGroup:
             this.attributeGroup = (XmlSchemaAttributeGroup)container;
             break;
         case State.AttributeGroupRef:
             this.attributeGroupRef = (XmlSchemaAttributeGroupRef)container;
             break;
         case State.AnyAttribute:
             this.anyAttribute = (XmlSchemaAnyAttribute)container;
             break;
         case State.Group:
             this.group = (XmlSchemaGroup)container;
             break;
         case State.GroupRef:
             this.groupRef = (XmlSchemaGroupRef)container;
             break;
         case State.All:
             this.all = (XmlSchemaAll)container;
             break;
         case State.Choice:
             this.choice = (XmlSchemaChoice)container;
             break;
         case State.Sequence:
             this.sequence = (XmlSchemaSequence)container;
             break;
         case State.Any:
             this.anyElement = (XmlSchemaAny)container;
             break;
         case State.Notation:
             this.notation = (XmlSchemaNotation)container;
             break;
         case State.SimpleType:
             this.simpleType = (XmlSchemaSimpleType)container;
             break;
         case State.ComplexType:
             this.complexType = (XmlSchemaComplexType)container;
             break;
         case State.ComplexContent:
             this.complexContent = (XmlSchemaComplexContent)container;
             break;
         case State.ComplexContentExtension:
             this.complexContentExtension = (XmlSchemaComplexContentExtension)container;
             break;
         case State.ComplexContentRestriction:
             this.complexContentRestriction = (XmlSchemaComplexContentRestriction)container;
             break;
         case State.SimpleContent:
             this.simpleContent = (XmlSchemaSimpleContent)container;
             break;
         case State.SimpleContentExtension:
             this.simpleContentExtension = (XmlSchemaSimpleContentExtension)container;
             break;
         case State.SimpleContentRestriction:
             this.simpleContentRestriction = (XmlSchemaSimpleContentRestriction)container;
             break;
         case State.SimpleTypeUnion:
             this.simpleTypeUnion = (XmlSchemaSimpleTypeUnion)container;
             break;
         case State.SimpleTypeList:
             this.simpleTypeList = (XmlSchemaSimpleTypeList)container;
             break;
         case State.SimpleTypeRestriction:
             this.simpleTypeRestriction = (XmlSchemaSimpleTypeRestriction)container;
             break;
         case State.Unique:
         case State.Key:
         case State.KeyRef:
             this.identityConstraint = (XmlSchemaIdentityConstraint)container;
             break;
         case State.Selector:
         case State.Field:
             this.xpath = (XmlSchemaXPath)container;
             break;
         case State.MinExclusive:
         case State.MinInclusive:
         case State.MaxExclusive:
         case State.MaxInclusive:
         case State.TotalDigits:
         case State.FractionDigits:
         case State.Length:
         case State.MinLength:
         case State.MaxLength:
         case State.Enumeration:
         case State.Pattern:
         case State.WhiteSpace:
             this.facet = (XmlSchemaFacet)container;
             break;
         case State.AppInfo:
             this.appInfo = (XmlSchemaAppInfo)container;
             break;
         case State.Documentation:
             this.documentation = (XmlSchemaDocumentation)container;
             break;
         case State.Redefine:
             this.redefine = (XmlSchemaRedefine)container;
             break;
         default:
             Debug.Assert(false, "State is " + state);
             break;
     }
 }
Example #27
0
		/// <summary>
		/// Creates the schema type representing the agent type
		/// </summary>
		/// <returns>Type definition for an agent</returns>
		static XmlSchemaType CreateAgentType()
		{
			XmlSchemaComplexContentExtension Extension = new XmlSchemaComplexContentExtension();
			Extension.BaseTypeName = GetQualifiedTypeName(ScriptSchemaStandardType.AgentBody);
			Extension.Attributes.Add(CreateSchemaAttribute("Name", StringTypeName, XmlSchemaUse.Required));
			Extension.Attributes.Add(CreateSchemaAttribute("Type", ScriptSchemaStandardType.NameList, XmlSchemaUse.Optional));
			Extension.Attributes.Add(CreateSchemaAttribute("If", ScriptSchemaStandardType.BalancedString, XmlSchemaUse.Optional));

			XmlSchemaComplexContent ContentModel = new XmlSchemaComplexContent();
			ContentModel.Content = Extension;

			XmlSchemaComplexType ComplexType = new XmlSchemaComplexType();
			ComplexType.Name = GetTypeName(ScriptSchemaStandardType.Agent);
			ComplexType.ContentModel = ContentModel;
			return ComplexType;
		}
		XmlCompletionDataCollection GetChildElementCompletionData(XmlSchemaComplexContent complexContent, string prefix)
		{
			XmlCompletionDataCollection data = new XmlCompletionDataCollection();
			
			XmlSchemaComplexContentExtension extension = complexContent.Content as XmlSchemaComplexContentExtension;
			if (extension != null) {
				data = GetChildElementCompletionData(extension, prefix);
			} else {
				XmlSchemaComplexContentRestriction restriction = complexContent.Content as XmlSchemaComplexContentRestriction;
				if (restriction != null) {
					data = GetChildElementCompletionData(restriction, prefix);
				}
			}
			
			return data;
		}
Example #29
0
		/// <summary>
		/// Creates the schema type representing the node type
		/// </summary>
		/// <returns>Type definition for a node</returns>
		static XmlSchemaType CreateNodeType()
		{
			XmlSchemaComplexContentExtension Extension = new XmlSchemaComplexContentExtension();
			Extension.BaseTypeName = GetQualifiedTypeName(ScriptSchemaStandardType.NodeBody);
			Extension.Attributes.Add(CreateSchemaAttribute("Name", ScriptSchemaStandardType.Name, XmlSchemaUse.Required));
			Extension.Attributes.Add(CreateSchemaAttribute("Requires", ScriptSchemaStandardType.NameOrTagList, XmlSchemaUse.Optional));
			Extension.Attributes.Add(CreateSchemaAttribute("Produces", ScriptSchemaStandardType.TagList, XmlSchemaUse.Optional));
			Extension.Attributes.Add(CreateSchemaAttribute("After", ScriptSchemaStandardType.NameOrTagList, XmlSchemaUse.Optional));
			Extension.Attributes.Add(CreateSchemaAttribute("Token", ScriptSchemaStandardType.BalancedString, XmlSchemaUse.Optional));
			Extension.Attributes.Add(CreateSchemaAttribute("If", ScriptSchemaStandardType.BalancedString, XmlSchemaUse.Optional));
			Extension.Attributes.Add(CreateSchemaAttribute("NotifyOnWarnings", ScriptSchemaStandardType.Boolean, XmlSchemaUse.Optional));

			XmlSchemaComplexContent ContentModel = new XmlSchemaComplexContent();
			ContentModel.Content = Extension;

			XmlSchemaComplexType ComplexType = new XmlSchemaComplexType();
			ComplexType.Name = GetTypeName(ScriptSchemaStandardType.Node);
			ComplexType.ContentModel = ContentModel;
			return ComplexType;
		}
Example #30
0
		/// <summary>
		/// Creates an element representing a conditional "Switch" block, which recursively contains another type
		/// </summary>
		/// <param name="InnerType">The base type for the do block to contain</param>
		/// <returns>New schema element for the block</returns>
		static XmlSchemaElement CreateSwitchElement(ScriptSchemaStandardType InnerType)
		{
			// Create the "Option" element
			XmlSchemaComplexContentExtension CaseExtension = new XmlSchemaComplexContentExtension();
			CaseExtension.BaseTypeName = GetQualifiedTypeName(InnerType);
			CaseExtension.Attributes.Add(CreateSchemaAttribute("If", ScriptSchemaStandardType.BalancedString, XmlSchemaUse.Required));

			XmlSchemaComplexContent CaseContentModel = new XmlSchemaComplexContent();
			CaseContentModel.Content = CaseExtension;

			XmlSchemaComplexType CaseSchemaType = new XmlSchemaComplexType();
			CaseSchemaType.ContentModel = CaseContentModel;

			XmlSchemaElement CaseElement = new XmlSchemaElement();
			CaseElement.Name = "Case";
			CaseElement.SchemaType = CaseSchemaType;
			CaseElement.MinOccurs = 0;
			CaseElement.MaxOccursString = "unbounded";

			// Create the "Otherwise" element
			XmlSchemaElement OtherwiseElement = new XmlSchemaElement();
			OtherwiseElement.Name = "Default";
			OtherwiseElement.SchemaTypeName = GetQualifiedTypeName(InnerType);
			OtherwiseElement.MinOccurs = 0;
			OtherwiseElement.MaxOccurs = 1;

			// Create the "Switch" element
			XmlSchemaSequence SwitchSequence = new XmlSchemaSequence();
			SwitchSequence.Items.Add(CaseElement);
			SwitchSequence.Items.Add(OtherwiseElement);

			XmlSchemaComplexType SwitchSchemaType = new XmlSchemaComplexType();
			SwitchSchemaType.Particle = SwitchSequence;

			XmlSchemaElement SwitchElement = new XmlSchemaElement();
			SwitchElement.Name = "Switch";
			SwitchElement.SchemaType = SwitchSchemaType;
			return SwitchElement;
		}
 private XmlQualifiedName ExportStructMapping(StructMapping mapping, string ns, XmlSchemaElement element)
 {
     if (mapping.TypeDesc.IsRoot)
     {
         this.needToExportRoot = true;
         return XmlQualifiedName.Empty;
     }
     if (mapping.IsAnonymousType)
     {
         if (this.references[mapping] != null)
         {
             throw new InvalidOperationException(Res.GetString("XmlCircularReference2", new object[] { mapping.TypeDesc.Name, "AnonymousType", "false" }));
         }
         this.references[mapping] = mapping;
     }
     XmlSchemaComplexType item = (XmlSchemaComplexType) this.types[mapping];
     if (item == null)
     {
         if (!mapping.IncludeInSchema)
         {
             throw new InvalidOperationException(Res.GetString("XmlCannotIncludeInSchema", new object[] { mapping.TypeDesc.Name }));
         }
         this.CheckForDuplicateType(mapping, mapping.Namespace);
         item = new XmlSchemaComplexType();
         if (!mapping.IsAnonymousType)
         {
             item.Name = mapping.TypeName;
             this.AddSchemaItem(item, mapping.Namespace, ns);
             this.types.Add(mapping, item);
         }
         item.IsAbstract = mapping.TypeDesc.IsAbstract;
         bool isOpenModel = mapping.IsOpenModel;
         if ((mapping.BaseMapping != null) && mapping.BaseMapping.IncludeInSchema)
         {
             if (mapping.BaseMapping.IsAnonymousType)
             {
                 throw new InvalidOperationException(Res.GetString("XmlAnonymousBaseType", new object[] { mapping.TypeDesc.Name, mapping.BaseMapping.TypeDesc.Name, "AnonymousType", "false" }));
             }
             if (mapping.HasSimpleContent)
             {
                 XmlSchemaSimpleContent content = new XmlSchemaSimpleContent();
                 XmlSchemaSimpleContentExtension extension = new XmlSchemaSimpleContentExtension {
                     BaseTypeName = this.ExportStructMapping(mapping.BaseMapping, mapping.Namespace, null)
                 };
                 content.Content = extension;
                 item.ContentModel = content;
             }
             else
             {
                 XmlSchemaComplexContentExtension extension2 = new XmlSchemaComplexContentExtension {
                     BaseTypeName = this.ExportStructMapping(mapping.BaseMapping, mapping.Namespace, null)
                 };
                 XmlSchemaComplexContent content2 = new XmlSchemaComplexContent {
                     Content = extension2,
                     IsMixed = XmlSchemaImporter.IsMixed((XmlSchemaComplexType) this.types[mapping.BaseMapping])
                 };
                 item.ContentModel = content2;
             }
             isOpenModel = false;
         }
         this.ExportTypeMembers(item, mapping.Members, mapping.TypeName, mapping.Namespace, mapping.HasSimpleContent, isOpenModel);
         this.ExportDerivedMappings(mapping);
         if (mapping.XmlnsMember != null)
         {
             this.AddXmlnsAnnotation(item, mapping.XmlnsMember.Name);
         }
     }
     else
     {
         this.AddSchemaImport(mapping.Namespace, ns);
     }
     if (mapping.IsAnonymousType)
     {
         this.references[mapping] = null;
         if (element != null)
         {
             element.SchemaType = item;
         }
         return XmlQualifiedName.Empty;
     }
     XmlQualifiedName name = new XmlQualifiedName(item.Name, mapping.Namespace);
     if (element != null)
     {
         element.SchemaTypeName = name;
     }
     return name;
 }
Example #32
0
		/// <summary>
		/// Creates an element representing a conditional "ForEach" block, which recursively contains another type
		/// </summary>
		/// <param name="InnerType">The base type for the foreach block to contain</param>
		/// <returns>New schema element for the block</returns>
		static XmlSchemaElement CreateForEachElement(ScriptSchemaStandardType InnerType)
		{
			XmlSchemaComplexContentExtension Extension = new XmlSchemaComplexContentExtension();
			Extension.BaseTypeName = GetQualifiedTypeName(InnerType);
			Extension.Attributes.Add(CreateSchemaAttribute("Name", ScriptSchemaStandardType.BalancedString, XmlSchemaUse.Required));
			Extension.Attributes.Add(CreateSchemaAttribute("Values", ScriptSchemaStandardType.BalancedString, XmlSchemaUse.Required));
			Extension.Attributes.Add(CreateSchemaAttribute("If", ScriptSchemaStandardType.BalancedString, XmlSchemaUse.Optional));

			XmlSchemaComplexContent ContentModel = new XmlSchemaComplexContent();
			ContentModel.Content = Extension;

			XmlSchemaComplexType SchemaType = new XmlSchemaComplexType();
			SchemaType.ContentModel = ContentModel;

			XmlSchemaElement Element = new XmlSchemaElement();
			Element.Name = "ForEach";
			Element.SchemaType = SchemaType;
			return Element;
		}
        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);
        }
        internal void ReflectStringParametersMessage() {
            Message inputMessage = InputMessage;
            foreach (ParameterInfo parameterInfo in Method.InParameters) {
                MessagePart part = new MessagePart();
                part.Name = XmlConvert.EncodeLocalName(parameterInfo.Name);
                if (parameterInfo.ParameterType.IsArray) {
                    string typeNs = DefaultNamespace;
                    if (typeNs.EndsWith("/", StringComparison.Ordinal))
                        typeNs += "AbstractTypes";
                    else
                        typeNs += "/AbstractTypes";
                    string typeName = "StringArray";
                    if (!ServiceDescription.Types.Schemas.Contains(typeNs)) {
                        XmlSchema schema = new XmlSchema();
                        schema.TargetNamespace = typeNs;
                        ServiceDescription.Types.Schemas.Add(schema);
                       
                        XmlSchemaElement element = new XmlSchemaElement();
                        element.Name = "String";
                        element.SchemaTypeName = new XmlQualifiedName("string", XmlSchema.Namespace);
                        element.MinOccurs = decimal.Zero;
                        element.MaxOccurs = decimal.MaxValue;
                        XmlSchemaSequence all = new XmlSchemaSequence();
                        all.Items.Add(element);

                        XmlSchemaComplexContentRestriction restriction = new XmlSchemaComplexContentRestriction();
                        restriction.BaseTypeName = new XmlQualifiedName(Soap.ArrayType, Soap.Encoding);
                        restriction.Particle = all;

                        XmlSchemaImport import = new XmlSchemaImport();
                        import.Namespace = restriction.BaseTypeName.Namespace;
                        
                        XmlSchemaComplexContent model = new XmlSchemaComplexContent();
                        model.Content = restriction;

                        XmlSchemaComplexType type = new XmlSchemaComplexType();
                        type.Name = typeName;
                        type.ContentModel = model;

                        schema.Items.Add(type);
                        schema.Includes.Add(import);
                    }
                    part.Type = new XmlQualifiedName(typeName, typeNs);
                }
                else {
                    part.Type = new XmlQualifiedName("string", XmlSchema.Namespace);
                }
                inputMessage.Parts.Add(part);
            }
        }
Example #35
0
		void ImportComplexContent (XmlQualifiedName typeQName, XmlTypeMapping map, XmlSchemaComplexContent content, CodeIdentifiers classIds, bool isMixed)
		{
			ClassMap cmap = (ClassMap)map.ObjectMap;
			XmlQualifiedName qname;

			XmlSchemaComplexContentExtension ext = content.Content as XmlSchemaComplexContentExtension;
			if (ext != null) qname = ext.BaseTypeName;
			else qname = ((XmlSchemaComplexContentRestriction)content.Content).BaseTypeName;
			
			if (qname == typeQName)
				throw new InvalidOperationException ("Cannot import schema for type '" + typeQName.Name + "' from namespace '" + typeQName.Namespace + "'. Redefine not supported");
			
			// Add base map members to this map

			XmlTypeMapping baseMap = ImportClass (qname);
			BuildPendingMap (baseMap);
			ClassMap baseClassMap = (ClassMap)baseMap.ObjectMap;

			foreach (XmlTypeMapMember member in baseClassMap.AllMembers)
				cmap.AddMember (member);

			if (baseClassMap.XmlTextCollector != null) isMixed = false;
			else if (content.IsMixed) isMixed = true;

			map.BaseMap = baseMap;
			baseMap.DerivedTypes.Add (map);

			if (ext != null) {
				// Add the members of this map
				ImportParticleComplexContent (typeQName, cmap, ext.Particle, classIds, isMixed);
				ImportAttributes (typeQName, cmap, ext.Attributes, ext.AnyAttribute, classIds);
			}
			else {
				if (isMixed) ImportParticleComplexContent (typeQName, cmap, null, classIds, true);
			}
		}
Example #36
0
        internal XmlSchemaObject Clone(XmlSchema?parentSchema)
        {
            XmlSchemaComplexType complexType = (XmlSchemaComplexType)MemberwiseClone();

            //Deep clone the QNames as these will be updated on chameleon includes
            if (complexType.ContentModel != null)
            { //simpleContent or complexContent
                XmlSchemaSimpleContent?simpleContent = complexType.ContentModel as XmlSchemaSimpleContent;
                if (simpleContent != null)
                {
                    XmlSchemaSimpleContent newSimpleContent = (XmlSchemaSimpleContent)simpleContent.Clone();

                    XmlSchemaSimpleContentExtension?simpleExt = simpleContent.Content as XmlSchemaSimpleContentExtension;
                    if (simpleExt != null)
                    {
                        XmlSchemaSimpleContentExtension newSimpleExt = (XmlSchemaSimpleContentExtension)simpleExt.Clone();
                        newSimpleExt.BaseTypeName = simpleExt.BaseTypeName.Clone();
                        newSimpleExt.SetAttributes(CloneAttributes(simpleExt.Attributes));
                        newSimpleContent.Content = newSimpleExt;
                    }
                    else
                    { //simpleContent.Content is XmlSchemaSimpleContentRestriction
                        XmlSchemaSimpleContentRestriction simpleRest    = (XmlSchemaSimpleContentRestriction)simpleContent.Content !;
                        XmlSchemaSimpleContentRestriction newSimpleRest = (XmlSchemaSimpleContentRestriction)simpleRest.Clone();
                        newSimpleRest.BaseTypeName = simpleRest.BaseTypeName.Clone();
                        newSimpleRest.SetAttributes(CloneAttributes(simpleRest.Attributes));
                        newSimpleContent.Content = newSimpleRest;
                    }

                    complexType.ContentModel = newSimpleContent;
                }
                else
                { // complexType.ContentModel is XmlSchemaComplexContent
                    XmlSchemaComplexContent complexContent    = (XmlSchemaComplexContent)complexType.ContentModel;
                    XmlSchemaComplexContent newComplexContent = (XmlSchemaComplexContent)complexContent.Clone();

                    XmlSchemaComplexContentExtension?complexExt = complexContent.Content as XmlSchemaComplexContentExtension;
                    if (complexExt != null)
                    {
                        XmlSchemaComplexContentExtension newComplexExt = (XmlSchemaComplexContentExtension)complexExt.Clone();
                        newComplexExt.BaseTypeName = complexExt.BaseTypeName.Clone();
                        newComplexExt.SetAttributes(CloneAttributes(complexExt.Attributes));
                        if (HasParticleRef(complexExt.Particle, parentSchema))
                        {
                            newComplexExt.Particle = CloneParticle(complexExt.Particle, parentSchema);
                        }
                        newComplexContent.Content = newComplexExt;
                    }
                    else
                    { // complexContent.Content is XmlSchemaComplexContentRestriction
                        XmlSchemaComplexContentRestriction complexRest    = (complexContent.Content as XmlSchemaComplexContentRestriction) !;
                        XmlSchemaComplexContentRestriction newComplexRest = (XmlSchemaComplexContentRestriction)complexRest.Clone();
                        newComplexRest.BaseTypeName = complexRest.BaseTypeName.Clone();
                        newComplexRest.SetAttributes(CloneAttributes(complexRest.Attributes));
                        if (HasParticleRef(newComplexRest.Particle, parentSchema))
                        {
                            newComplexRest.Particle = CloneParticle(newComplexRest.Particle, parentSchema);
                        }

                        newComplexContent.Content = newComplexRest;
                    }

                    complexType.ContentModel = newComplexContent;
                }
            }
            else
            { //equals XmlSchemaComplexContent with baseType is anyType
                if (HasParticleRef(complexType.Particle, parentSchema))
                {
                    complexType.Particle = CloneParticle(complexType.Particle, parentSchema);
                }
                complexType.SetAttributes(CloneAttributes(complexType.Attributes));
            }
            complexType.ClearCompiledState();
            return(complexType);
        }
 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);
     }
 }
Example #38
0
 XmlQualifiedName ExportStructMapping(StructMapping mapping, string ns, XmlSchemaElement element) {
     if (mapping.TypeDesc.IsRoot) {
         needToExportRoot = true;
         return XmlQualifiedName.Empty;
     }
     if (mapping.IsAnonymousType) {
         if (references[mapping] != null)
             throw new InvalidOperationException(Res.GetString(Res.XmlCircularReference2, mapping.TypeDesc.Name, "AnonymousType", "false"));
         references[mapping] = mapping;
     }
     XmlSchemaComplexType type = (XmlSchemaComplexType)types[mapping];
     if (type == null) {
         if (!mapping.IncludeInSchema) throw new InvalidOperationException(Res.GetString(Res.XmlCannotIncludeInSchema, mapping.TypeDesc.Name));
         CheckForDuplicateType(mapping, mapping.Namespace);
         type = new XmlSchemaComplexType();
         if (!mapping.IsAnonymousType) {
             type.Name = mapping.TypeName;
             AddSchemaItem(type, mapping.Namespace, ns);
             types.Add(mapping, type);
         }
         type.IsAbstract = mapping.TypeDesc.IsAbstract;
         bool openModel = mapping.IsOpenModel;
         if (mapping.BaseMapping != null && mapping.BaseMapping.IncludeInSchema) {
             if (mapping.BaseMapping.IsAnonymousType) {
                 throw new InvalidOperationException(Res.GetString(Res.XmlAnonymousBaseType, mapping.TypeDesc.Name, mapping.BaseMapping.TypeDesc.Name, "AnonymousType", "false"));
             }
             if (mapping.HasSimpleContent) {
                 XmlSchemaSimpleContent model = new XmlSchemaSimpleContent();
                 XmlSchemaSimpleContentExtension extension = new XmlSchemaSimpleContentExtension();
                 extension.BaseTypeName = ExportStructMapping(mapping.BaseMapping, mapping.Namespace, null);
                 model.Content = extension;
                 type.ContentModel = model;
             }
             else {
                 XmlSchemaComplexContentExtension extension = new XmlSchemaComplexContentExtension();
                 extension.BaseTypeName = ExportStructMapping(mapping.BaseMapping, mapping.Namespace, null);
                 XmlSchemaComplexContent model = new XmlSchemaComplexContent();
                 model.Content = extension;
                 model.IsMixed = XmlSchemaImporter.IsMixed((XmlSchemaComplexType)types[mapping.BaseMapping]);
                 type.ContentModel = model;
             }
             openModel = false;
         }
         ExportTypeMembers(type, mapping.Members, mapping.TypeName, mapping.Namespace, mapping.HasSimpleContent, openModel);
         ExportDerivedMappings(mapping);
         if (mapping.XmlnsMember != null) {
             AddXmlnsAnnotation(type, mapping.XmlnsMember.Name);
         }
     }
     else {
         AddSchemaImport(mapping.Namespace, ns);
     }
     if (mapping.IsAnonymousType) {
         references[mapping] = null;
         if (element != null) 
             element.SchemaType = type;
         return XmlQualifiedName.Empty;
     }
     else {
         XmlQualifiedName qname = new XmlQualifiedName(type.Name, mapping.Namespace);
         if (element != null) element.SchemaTypeName = qname;
         return qname;
     }
 }
 private XmlSchemaContentType GetSchemaContentType(XmlSchemaComplexType complexType, XmlSchemaComplexContent complexContent, XmlSchemaParticle particle)
 {
     if (((complexContent != null) && complexContent.IsMixed) || ((complexContent == null) && complexType.IsMixed))
     {
         return XmlSchemaContentType.Mixed;
     }
     if ((particle != null) && !particle.IsEmpty)
     {
         return XmlSchemaContentType.ElementOnly;
     }
     return XmlSchemaContentType.Empty;
 }
        internal static XmlSchemaComplexContent Read(XmlSchemaReader reader, ValidationEventHandler h)
        {
            XmlSchemaComplexContent xmlSchemaComplexContent = new XmlSchemaComplexContent();

            reader.MoveToElement();
            if (reader.NamespaceURI != "http://www.w3.org/2001/XMLSchema" || reader.LocalName != "complexContent")
            {
                XmlSchemaObject.error(h, "Should not happen :1: XmlSchemaComplexContent.Read, name=" + reader.Name, null);
                reader.Skip();
                return(null);
            }
            xmlSchemaComplexContent.LineNumber   = reader.LineNumber;
            xmlSchemaComplexContent.LinePosition = reader.LinePosition;
            xmlSchemaComplexContent.SourceUri    = reader.BaseURI;
            while (reader.MoveToNextAttribute())
            {
                if (reader.Name == "id")
                {
                    xmlSchemaComplexContent.Id = reader.Value;
                }
                else if (reader.Name == "mixed")
                {
                    Exception ex;
                    xmlSchemaComplexContent.isMixed = XmlSchemaUtil.ReadBoolAttribute(reader, out ex);
                    if (ex != null)
                    {
                        XmlSchemaObject.error(h, reader.Value + " is an invalid value for mixed", ex);
                    }
                }
                else if ((reader.NamespaceURI == string.Empty && reader.Name != "xmlns") || reader.NamespaceURI == "http://www.w3.org/2001/XMLSchema")
                {
                    XmlSchemaObject.error(h, reader.Name + " is not a valid attribute for complexContent", null);
                }
                else
                {
                    XmlSchemaUtil.ReadUnhandledAttribute(reader, xmlSchemaComplexContent);
                }
            }
            reader.MoveToElement();
            if (reader.IsEmptyElement)
            {
                return(xmlSchemaComplexContent);
            }
            int num = 1;

            while (reader.ReadNextElement())
            {
                if (reader.NodeType == XmlNodeType.EndElement)
                {
                    if (reader.LocalName != "complexContent")
                    {
                        XmlSchemaObject.error(h, "Should not happen :2: XmlSchemaComplexContent.Read, name=" + reader.Name, null);
                    }
                    break;
                }
                if (num <= 1 && reader.LocalName == "annotation")
                {
                    num = 2;
                    XmlSchemaAnnotation xmlSchemaAnnotation = XmlSchemaAnnotation.Read(reader, h);
                    if (xmlSchemaAnnotation != null)
                    {
                        xmlSchemaComplexContent.Annotation = xmlSchemaAnnotation;
                    }
                }
                else
                {
                    if (num <= 2)
                    {
                        if (reader.LocalName == "restriction")
                        {
                            num = 3;
                            XmlSchemaComplexContentRestriction xmlSchemaComplexContentRestriction = XmlSchemaComplexContentRestriction.Read(reader, h);
                            if (xmlSchemaComplexContentRestriction != null)
                            {
                                xmlSchemaComplexContent.content = xmlSchemaComplexContentRestriction;
                            }
                            continue;
                        }
                        if (reader.LocalName == "extension")
                        {
                            num = 3;
                            XmlSchemaComplexContentExtension xmlSchemaComplexContentExtension = XmlSchemaComplexContentExtension.Read(reader, h);
                            if (xmlSchemaComplexContentExtension != null)
                            {
                                xmlSchemaComplexContent.content = xmlSchemaComplexContentExtension;
                            }
                            continue;
                        }
                    }
                    reader.RaiseInvalidElementError();
                }
            }
            return(xmlSchemaComplexContent);
        }