/// <summary> /// Register an XS:Choice /// </summary> /// <param name="c">The XS:Choice to register</param> protected void RegisterChoice(System.Xml.Schema.XmlSchemaChoice c) { XmlSchemaChoice chce = new XmlSchemaChoice(Schema, this); chce.Load(c); content = chce; }
/// <summary> /// Register an XS:Sequence /// </summary> /// <param name="s">The XS:Sequence to register</param> protected void RegisterSequence(System.Xml.Schema.XmlSchemaSequence s) { XmlSchemaSequence seq = new XmlSchemaSequence(Schema, this); seq.Load(s); List <Object> gc = new List <object>(); // Clean sequence foreach (XmlSchemaObject o in seq.Content) { XmlSchemaComplexType prnt = (XmlSchemaComplexType)this.BaseClass; while (prnt != null) { prnt.Compile(); if (prnt.Content != null) { foreach (XmlSchemaObject ot in prnt.Content) { if (o.GetType() == ot.GetType() && o.Name == ot.Name && ot.Namespace == o.Namespace && (o as XmlSchemaComplexContent).MinOccurs == (ot as XmlSchemaComplexContent).MinOccurs && (o as XmlSchemaComplexContent).MaxOccurs == (ot as XmlSchemaComplexContent).MaxOccurs) // Found so we don't need it { gc.Add(o); } else if (o.GetType() == ot.GetType() && o.Name == ot.Name && ot.Namespace == o.Namespace && o.MifData == null) // Copy mif data as it may be useful (this is most likely a restriction) { o.MifData = ot.MifData; } } } prnt = (XmlSchemaComplexType)prnt.BaseClass; } } // Clean garbage foreach (Object o in gc) { seq.Content.Remove(o as XmlSchemaObject); } content = seq; }
/// <summary> /// Compile this type /// </summary> public void Compile() { if (compiled) { return; } System.Xml.Schema.XmlSchemaComplexType type = (schemaPtr as System.Xml.Schema.XmlSchemaComplexType); // Load attributes (HL7 schemas like AttributeUses foreach (System.Xml.Schema.XmlSchemaObject o in type.AttributeUses.Values) { if (o is System.Xml.Schema.XmlSchemaAttributeGroup) { foreach (System.Xml.Schema.XmlSchemaObject xso in (o as System.Xml.Schema.XmlSchemaAttributeGroup).Attributes) { RegisterAttribute(xso as System.Xml.Schema.XmlSchemaAttribute); } } else if (o is System.Xml.Schema.XmlSchemaAttribute && (o as System.Xml.Schema.XmlSchemaAttribute).Name != null) { RegisterAttribute(o as System.Xml.Schema.XmlSchemaAttribute); } } // Load Complex Elements if (type.Particle != null) { RegisterContent(type.Particle); } else if (type.ContentModel is System.Xml.Schema.XmlSchemaComplexContent) { // Correct base class if possible if (BaseClass == null && type.ContentModel.Content is System.Xml.Schema.XmlSchemaComplexContentExtension) // Determine base class { this.BaseClass = Schema.FindType((type.ContentModel.Content as System.Xml.Schema.XmlSchemaComplexContentExtension).BaseTypeName.Name); } // Go through the particle(s) if (type.ContentModel.Content is System.Xml.Schema.XmlSchemaComplexContentExtension) { RegisterContent((type.ContentModel.Content as System.Xml.Schema.XmlSchemaComplexContentExtension).Particle); } else if (type.ContentModel.Content is System.Xml.Schema.XmlSchemaComplexContentRestriction) { RegisterRestriction((type.ContentModel.Content as System.Xml.Schema.XmlSchemaComplexContentRestriction).Particle); } // If sequence is null then create an empty one if (Content == null) { content = new XmlSchemaSequence(Schema, this); } } else { // Simple content } compiled = true; }