Code Generated from KML Schema Incomplete

Jul 8, 2011 at 10:10 PM

I need to be able to work with the latest KML standard schema, located at  I've run this xsd through the latest version of Xsd2Code and get many compilation errors in the resulting code.  They all involve properties that reference member variables that are never declared.  Most of them are properties whose types are defined as abstract in the xsd.  It seems that Xsd2Code doesn't treat these abstract elements the same way it treats other elements.  For example:


    [System.Runtime.Serialization.DataContractAttribute(Name = "KmlType", Namespace = "")]
    public partial class KmlType

        private NetworkLinkControlType networkLinkControlField;

        private List<string> kmlSimpleExtensionGroupField;

        private List<AbstractObjectType> kmlObjectExtensionGroupField;

        private string hintField;

        private static System.Xml.Serialization.XmlSerializer serializer;

        private bool networkLinkControlFieldSpecified;

        private bool itemFieldSpecified;

        private bool kmlSimpleExtensionGroupFieldSpecified;

        private bool kmlObjectExtensionGroupFieldSpecified;

        private bool hintFieldSpecified;

        public string hint { get; set; }

        public KmlType()
            this.kmlObjectExtensionGroupField = new List<AbstractObjectType>();
            this.kmlSimpleExtensionGroupField = new List<string>();
            this.networkLinkControlField = new NetworkLinkControlType();

        public AbstractFeatureType Item
                return this.itemField;
                this.itemField = value;

/* Code omitted for brevity */
Note that there is NO member variable called "itemField" in the class declaration.  In addition, where the element in the XSD is named "AbstractFeatureGroup", the property is incorrectly named Item.

Here are the portions of the XSD that define this property.

  <complexType name="KmlType" final="#all">
      <element ref="kml:NetworkLinkControl" minOccurs="0"/>
      <element ref="kml:AbstractFeatureGroup" minOccurs="0"/>
      <element ref="kml:KmlSimpleExtensionGroup" minOccurs="0"
      <element ref="kml:KmlObjectExtensionGroup" minOccurs="0"
    <attribute name="hint" type="string"/>
  <!-- Code omitted for brevity -->

  <element name="AbstractFeatureGroup" type="kml:AbstractFeatureType"
    abstract="true" substitutionGroup="kml:AbstractObjectGroup"/>

Perhaps I'm not using the proper settings for the tool. I'm not sure since I didn't see any documentation on the CodePlex site.

Any help will be greatly appreciated.



Jul 8, 2011 at 10:42 PM

After playing with the Xsd2Code settings, I found that this problem only occurs if the setting AutomaticProperties = true.  I'm not sure what this setting does, but I'm leaving it set to false.