private void CompileComplexType(XmlSchemaComplexType complexType) { if (complexType.ElementDecl != null) { //already compiled return; } if (complexType.IsProcessing) { SendValidationEvent(Res.Sch_TypeCircularRef, complexType); return; } complexType.IsProcessing = true; try { if (complexType.ContentModel != null) { //simpleContent or complexContent if (complexType.ContentModel is XmlSchemaSimpleContent) { XmlSchemaSimpleContent simpleContent = (XmlSchemaSimpleContent)complexType.ContentModel; complexType.SetContentType(XmlSchemaContentType.TextOnly); if (simpleContent.Content is XmlSchemaSimpleContentExtension) { CompileSimpleContentExtension(complexType, (XmlSchemaSimpleContentExtension)simpleContent.Content); } else { //simpleContent.Content is XmlSchemaSimpleContentRestriction CompileSimpleContentRestriction(complexType, (XmlSchemaSimpleContentRestriction)simpleContent.Content); } } else { // complexType.ContentModel is XmlSchemaComplexContent XmlSchemaComplexContent complexContent = (XmlSchemaComplexContent)complexType.ContentModel; if (complexContent.Content is XmlSchemaComplexContentExtension) { CompileComplexContentExtension(complexType, complexContent, (XmlSchemaComplexContentExtension)complexContent.Content); } else { // complexContent.Content is XmlSchemaComplexContentRestriction CompileComplexContentRestriction(complexType, complexContent, (XmlSchemaComplexContentRestriction)complexContent.Content); } } } else { //equals XmlSchemaComplexContent with baseType is anyType complexType.SetBaseSchemaType(XmlSchemaComplexType.AnyType); CompileLocalAttributes(XmlSchemaComplexType.AnyType, complexType, complexType.Attributes, complexType.AnyAttribute, XmlSchemaDerivationMethod.Restriction); complexType.SetDerivedBy(XmlSchemaDerivationMethod.Restriction); complexType.SetContentTypeParticle(CompileContentTypeParticle(complexType.Particle)); complexType.SetContentType(GetSchemaContentType(complexType, null, complexType.ContentTypeParticle)); } if (complexType.ContainsIdAttribute(true)) { SendValidationEvent(Res.Sch_TwoIdAttrUses, complexType); } SchemaElementDecl decl = new SchemaElementDecl(); decl.ContentValidator = CompileComplexContent(complexType); decl.SchemaType = complexType; decl.IsAbstract = complexType.IsAbstract; decl.Datatype = complexType.Datatype; decl.Block = complexType.BlockResolved; decl.AnyAttribute = complexType.AttributeWildcard; foreach(XmlSchemaAttribute attribute in complexType.AttributeUses.Values) { if (attribute.Use == XmlSchemaUse.Prohibited) { if (!decl.ProhibitedAttributes.ContainsKey(attribute.QualifiedName)) { decl.ProhibitedAttributes.Add(attribute.QualifiedName, attribute.QualifiedName); } } else { if (!decl.AttDefs.ContainsKey(attribute.QualifiedName) && attribute.AttDef != null && attribute.AttDef.Name != XmlQualifiedName.Empty && attribute.AttDef != SchemaAttDef.Empty) { decl.AddAttDef(attribute.AttDef); } } } complexType.ElementDecl = decl; } finally { complexType.IsProcessing = false; } }
private void CompileComplexType(XmlSchemaComplexType complexType) { if (complexType.ElementDecl == null) { if (complexType.IsProcessing) { base.SendValidationEvent("Sch_TypeCircularRef", complexType); } else { complexType.IsProcessing = true; if (complexType.ContentModel != null) { if (complexType.ContentModel is XmlSchemaSimpleContent) { XmlSchemaSimpleContent contentModel = (XmlSchemaSimpleContent) complexType.ContentModel; complexType.SetContentType(XmlSchemaContentType.TextOnly); if (contentModel.Content is XmlSchemaSimpleContentExtension) { this.CompileSimpleContentExtension(complexType, (XmlSchemaSimpleContentExtension) contentModel.Content); } else { this.CompileSimpleContentRestriction(complexType, (XmlSchemaSimpleContentRestriction) contentModel.Content); } } else { XmlSchemaComplexContent complexContent = (XmlSchemaComplexContent) complexType.ContentModel; if (complexContent.Content is XmlSchemaComplexContentExtension) { this.CompileComplexContentExtension(complexType, complexContent, (XmlSchemaComplexContentExtension) complexContent.Content); } else { this.CompileComplexContentRestriction(complexType, complexContent, (XmlSchemaComplexContentRestriction) complexContent.Content); } } } else { complexType.SetBaseSchemaType(XmlSchemaComplexType.AnyType); this.CompileLocalAttributes(XmlSchemaComplexType.AnyType, complexType, complexType.Attributes, complexType.AnyAttribute, XmlSchemaDerivationMethod.Restriction); complexType.SetDerivedBy(XmlSchemaDerivationMethod.Restriction); complexType.SetContentTypeParticle(this.CompileContentTypeParticle(complexType.Particle, true)); complexType.SetContentType(this.GetSchemaContentType(complexType, null, complexType.ContentTypeParticle)); } bool flag = false; foreach (XmlSchemaAttribute attribute in complexType.AttributeUses.Values) { if (attribute.Use != XmlSchemaUse.Prohibited) { XmlSchemaDatatype datatype = attribute.Datatype; if ((datatype != null) && (datatype.TokenizedType == XmlTokenizedType.ID)) { if (flag) { base.SendValidationEvent("Sch_TwoIdAttrUses", complexType); } else { flag = true; } } } } SchemaElementDecl decl = new SchemaElementDecl { ContentValidator = this.CompileComplexContent(complexType), SchemaType = complexType, IsAbstract = complexType.IsAbstract, Datatype = complexType.Datatype, Block = complexType.BlockResolved, AnyAttribute = complexType.AttributeWildcard }; foreach (XmlSchemaAttribute attribute2 in complexType.AttributeUses.Values) { if (attribute2.Use == XmlSchemaUse.Prohibited) { if (!decl.ProhibitedAttributes.ContainsKey(attribute2.QualifiedName)) { decl.ProhibitedAttributes.Add(attribute2.QualifiedName, attribute2.QualifiedName); } } else if ((!decl.AttDefs.ContainsKey(attribute2.QualifiedName) && (attribute2.AttDef != null)) && ((attribute2.AttDef.Name != XmlQualifiedName.Empty) && (attribute2.AttDef != SchemaAttDef.Empty))) { decl.AddAttDef(attribute2.AttDef); } } complexType.ElementDecl = decl; complexType.IsProcessing = false; } } }
private void CompileComplexType(XmlSchemaComplexType complexType) { if (complexType.ElementDecl != null) { //already compiled return; } if (complexType.Validating) { SendValidationEvent(Res.Sch_TypeCircularRef, complexType); return; } complexType.Validating = true; CompiledContentModel compiledContentModel = new CompiledContentModel(this.schemaNames); if (complexType.ContentModel != null) { //simpleContent or complexContent if (complexType.ContentModel is XmlSchemaSimpleContent) { XmlSchemaSimpleContent simpleContent = (XmlSchemaSimpleContent)complexType.ContentModel; complexType.SetContentType(XmlSchemaContentType.TextOnly); if (simpleContent.Content is XmlSchemaSimpleContentExtension) { CompileSimpleContentExtension(complexType, (XmlSchemaSimpleContentExtension)simpleContent.Content); } else { //simpleContent.Content is XmlSchemaSimpleContentRestriction CompileSimpleContentRestriction(complexType, (XmlSchemaSimpleContentRestriction)simpleContent.Content); } } else { // complexType.ContentModel is XmlSchemaComplexContent XmlSchemaComplexContent complexContent = (XmlSchemaComplexContent)complexType.ContentModel; if (complexContent.Content is XmlSchemaComplexContentExtension) { CompileComplexContentExtension(complexType, complexContent, (XmlSchemaComplexContentExtension)complexContent.Content); } else { // complexContent.Content is XmlSchemaComplexContentRestriction CompileComplexContentRestriction(complexType, complexContent, (XmlSchemaComplexContentRestriction)complexContent.Content); } CompileComplexContent(complexType, compiledContentModel); } } else { //equals XmlSchemaComplexContent with baseType is anyType CompileLocalAttributes(XmlSchemaComplexType.AnyType, complexType, complexType.Attributes, complexType.AnyAttribute, XmlSchemaDerivationMethod.Restriction); complexType.SetDerivedBy(XmlSchemaDerivationMethod.Restriction); complexType.SetContentTypeParticle(CompileContentTypeParticle(complexType.Particle, true)); complexType.SetContentType(GetSchemaContentType(complexType, null, complexType.ContentTypeParticle)); CompileComplexContent(complexType, compiledContentModel); } bool hasID = false; foreach(XmlSchemaAttribute attribute in complexType.AttributeUses.Values) { if (attribute.Use != XmlSchemaUse.Prohibited) { XmlSchemaDatatype datatype = attribute.Datatype; if (datatype != null && datatype.TokenizedType == XmlTokenizedType.ID) { if (hasID) { SendValidationEvent(Res.Sch_TwoIdAttrUses, complexType); } else { hasID = true; } } } } SchemaElementDecl decl = new SchemaElementDecl(); decl.Content = compiledContentModel; decl.Content = compiledContentModel; decl.SchemaType = complexType; decl.Datatype = complexType.Datatype; decl.Block = complexType.BlockResolved; switch (complexType.ContentType) { case XmlSchemaContentType.TextOnly : decl.Content.ContentType = CompiledContentModel.Type.Text; break; case XmlSchemaContentType.Empty : decl.Content.ContentType = CompiledContentModel.Type.Empty; break; case XmlSchemaContentType.ElementOnly : decl.Content.ContentType = CompiledContentModel.Type.ElementOnly; break; default: decl.Content.ContentType = CompiledContentModel.Type.Mixed; break; } decl.AnyAttribute = complexType.AttributeWildcard; foreach(XmlSchemaAttribute attribute in complexType.AttributeUses.Values) { if (attribute.Use == XmlSchemaUse.Prohibited) { if (decl.ProhibitedAttributes[attribute.QualifiedName] == null) { decl.ProhibitedAttributes.Add(attribute.QualifiedName, attribute.QualifiedName); } } else { if (decl.AttDefs[attribute.QualifiedName] == null && attribute.AttDef != null && attribute.AttDef != SchemaAttDef.Empty) { decl.AddAttDef(attribute.AttDef); } } } complexType.ElementDecl = decl; complexType.Validating = false; }