substitutionGroup attribute

Feb 2, 2012 at 5:53 PM

I have been working with this tool to turn an xsd into classes, which works great.

I have seen some unexpected behavior with the following snippet of xsd. I believe it may be caused by the way that the substitutionGroup attribute is used.

Definition of nc in <xsd:schema xmlns:nc="http://niem.gov/niem/niem-core/2.0" />
 <xsd:element name="StructuredAddress" type="nc:StructuredAddressType" substitutionGroup="nc:AddressRepresentation" nillable="true">
    <xsd:annotation>
      <xsd:appinfo>
        <i:Base i:name="AddressRepresentation"/>
      </xsd:appinfo>
    </xsd:annotation>
  </xsd:element>

It produces the below code where StructuredAdress is an array of objects like below. Is this a result of incorrect settings or a function of the xsd's restrictions.

    [System.CodeDom.Compiler.GeneratedCodeAttribute("xsd", "4.0.30319.1")]
    [System.SerializableAttribute()]
    [System.Diagnostics.DebuggerStepThroughAttribute()]
    [System.ComponentModel.DesignerCategoryAttribute("code")]
    [System.Xml.Serialization.XmlTypeAttribute(Namespace="http://niem.gov/niem/niem-core/2.0")]
    [System.Xml.Serialization.XmlRootAttribute("LocationAddress", Namespace="http://niem.gov/niem/niem-core/2.0", IsNullable=true)]
    public partial class AddressType : ComplexObjectType {
       
        private object[] itemsField;
        /// <remarks/>
        [System.Xml.Serialization.XmlElementAttribute("AddressFullText", typeof(TextType), IsNullable=true)]
        [System.Xml.Serialization.XmlElementAttribute("StructuredAddress", typeof(StructuredAddressType), IsNullable=true)]
        public object[] Items {
            get {
                return this.itemsField;
            }
            set {
                this.itemsField = value;
            }
        }
    }

I would think that it would return something more like the below.

    [System.CodeDom.Compiler.GeneratedCodeAttribute("xsd", "4.0.30319.1")]
    [System.SerializableAttribute()]
    [System.Diagnostics.DebuggerStepThroughAttribute()]
    [System.ComponentModel.DesignerCategoryAttribute("code")]
    [System.Xml.Serialization.XmlTypeAttribute(Namespace="http://niem.gov/niem/niem-core/2.0")]
    [System.Xml.Serialization.XmlRootAttribute("LocationAddress", Namespace="http://niem.gov/niem/niem-core/2.0", IsNullable=true)]
    public partial class AddressType : ComplexObjectType
   {
           private StructuredAddressType[] structuredAddressField;
                                
          [System.Xml.Serialization.XmlElementAttribute("StructuredAddress", typeof(StructuredAddressType), IsNullable=true)]
          public StructuredAddressType[] StructuredAddress 
          {
                 get {  return this.structuredAddressField;  }
                 set {   this.structuredAddressField = value; }
            }
    }

Please let me know if you need more information.