title: xsd.exe generates weird C# class for XML serialization
body: <p>I have an XML schema in .xdr file. This is a shortened version of this file(just for example):    <br/> <br/></p>
  
  <pre><code>&lt;?xml version = "1.0" encoding = "WINDOWS-1252"?&gt;  
  &lt;Schema name = "ANS.xdr"
  xmlns = "urn:schemas-microsoft-com:xml-data"  
  xmlns:dt = "urn:schemas-microsoft-com:datatypes"&gt;  
   &lt;ElementType name = "Shipment" content = "eltOnly" order = "seq" model = "closed"&gt;  
    &lt;element type = "TrackingNumber" minOccurs = "0" maxOccurs = "1"/&gt;  
   &lt;/ElementType&gt;  
   &lt;ElementType name = "TrackingNumber" content = "textOnly" dt:type = "string" model = "closed"/&gt;  
  &lt;/Schema&gt;  
  </code></pre>
  
  <p>Using xsd.exe to translate this file into XSD format it poduces following file:</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt;
  &lt;xs:schema id="ANS.xdr" xmlns="" xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata"&gt;
    &lt;xs:element name="ANS.xdr" msdata:IsDataSet="true" msdata:UseCurrentLocale="true"&gt;
      &lt;xs:complexType&gt;
        &lt;xs:choice minOccurs="0" maxOccurs="unbounded"&gt;
          &lt;xs:element name="Shipment"&gt;
            &lt;xs:complexType&gt;
              &lt;xs:sequence&gt;
                &lt;xs:element name="TrackingNumber" type="xs:string" minOccurs="0" /&gt;
              &lt;/xs:sequence&gt;
            &lt;/xs:complexType&gt;
          &lt;/xs:element&gt;
        &lt;/xs:choice&gt;
      &lt;/xs:complexType&gt;
    &lt;/xs:element&gt;
  &lt;/xs:schema&gt;
  </code></pre>
  
  <p>Finally I am able to generate <code>.cs</code> file for XML serialization by:
  <code>xsd.exe /c ANS.xsd</code> which results in:</p>
  
  <pre><code>using System.Xml.Serialization;
  
  // 
  // This source code was auto-generated by xsd, Version=2.0.50727.3038.
  // 
  
  
  /// &lt;uwagi/&gt;
  [System.CodeDom.Compiler.GeneratedCodeAttribute("xsd", "2.0.50727.3038")]
  [System.SerializableAttribute()]
  [System.Diagnostics.DebuggerStepThroughAttribute()]
  [System.ComponentModel.DesignerCategoryAttribute("code")]
  [System.Xml.Serialization.XmlTypeAttribute(AnonymousType=true)]
  [System.Xml.Serialization.XmlRootAttribute("ANS.xdr", Namespace="", IsNullable=false)]
  public partial class ANSxdr {
  
      private ANSxdrShipment[] itemsField;
  
      /// &lt;uwagi/&gt;
      [System.Xml.Serialization.XmlElementAttribute("Shipment", Form=System.Xml.Schema.XmlSchemaForm.Unqualified)]
      public ANSxdrShipment[] Items {
          get {
              return this.itemsField;
          }
          set {
              this.itemsField = value;
          }
      }
  }
  
  /// &lt;uwagi/&gt;
  [System.CodeDom.Compiler.GeneratedCodeAttribute("xsd", "2.0.50727.3038")]
  [System.SerializableAttribute()]
  [System.Diagnostics.DebuggerStepThroughAttribute()]
  [System.ComponentModel.DesignerCategoryAttribute("code")]
  [System.Xml.Serialization.XmlTypeAttribute(AnonymousType=true)]
  public partial class ANSxdrShipment {
  
      private string trackingNumberField;
  
      /// &lt;uwagi/&gt;
      [System.Xml.Serialization.XmlElementAttribute(Form=System.Xml.Schema.XmlSchemaForm.Unqualified)]
      public string TrackingNumber {
          get {
              return this.trackingNumberField;
          }
          set {
              this.trackingNumberField = value;
          }
      }
  }
  </code></pre>
  
  <p>The problem is that <code>xsd.exe</code> adds prefix from schema name to the class name: <code>public partial class ANSxdrShipment</code> where shoud be just <code>Shipment</code>. It results in wrong tag names after serialization:</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt;
  &lt;ANSxdrShipment xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema"&gt;
    &lt;TrackingNumber&gt;PN-34-23414&lt;/TrackingNumber&gt;
  &lt;/ANSxdrShipment&gt;
  </code></pre>
  
  <p>I could just do manual corrects but the problem seems to aggregate when there are embedded ElementTypes. It results in extra long names, especially in complexed schemas, for example:</p>
  
  <p><code>OpenShipmentsxdrOpenShipmentsOpenShipmentShipmentReturnNotificationDetailsReturnNotificationNotificationEMailAddress</code></p>