0

I have an XSD file:

<xs:schema id="collections" xmlns="" xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata" targetNamespace="myNamespace" >
  <xs:element name="collections" msdata:IsDataSet="true" msdata:Locale="en-US">
    <xs:complexType>
      <xs:choice minOccurs="0" maxOccurs="unbounded">
        <xs:element name="collection">
          <xs:complexType>
            <xs:sequence>
              <xs:element name="collectionDetails" minOccurs="0" maxOccurs="unbounded">
                <xs:complexType>
                  <xs:sequence>
                    <xs:element name="transaction" minOccurs="0" maxOccurs="unbounded">
                    </xs:element>
                  </xs:sequence>
                  <xs:attribute name="Prop1" type="xs:string" />
                  <xs:attribute name="AccNo" type="xs:string" />
                </xs:complexType>
              </xs:element>
            </xs:sequence>
          </xs:complexType>
        </xs:element>
      </xs:choice>
    </xs:complexType>
  </xs:element>
</xs:schema>

if I parse this xsd with

xsd.exe "my.xsd" /c  /n:"CollectionMessage" 

I get the following output

namespace CollectionMessage {
    using System.Xml.Serialization;

    [System.CodeDom.Compiler.GeneratedCodeAttribute("xsd", "2.0.50727.3038")]
    [System.SerializableAttribute()]
    [System.Diagnostics.DebuggerStepThroughAttribute()]
    [System.ComponentModel.DesignerCategoryAttribute("code")]
    [System.Xml.Serialization.XmlTypeAttribute(AnonymousType=true, Namespace="myNamespace")]
    [System.Xml.Serialization.XmlRootAttribute(Namespace="myNamespace", IsNullable=false)]
    public partial class collections {

        private collectionsCollection[] itemsField;

        /// <remarks/>
        [System.Xml.Serialization.XmlElementAttribute("collection", Form=System.Xml.Schema.XmlSchemaForm.Unqualified)]
        public collectionsCollection[] Items {
            get {
                return this.itemsField;
            }
            set {
                this.itemsField = value;
            }
        }
    }

    [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 collectionsCollection {

        private collectionsCollectionCollectionDetails[] collectionDetailsField;
        [System.Xml.Serialization.XmlElementAttribute("collectionDetails", Form=System.Xml.Schema.XmlSchemaForm.Unqualified)]
        public collectionsCollectionCollectionDetails[] collectionDetails {
            get {
                return this.collectionDetailsField;
            }
            set {
                this.collectionDetailsField = value;
            }
        }
    }

    [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 collectionsCollectionCollectionDetails {

        private object[] transactionField;

        private string prop1Field;

        private string accNoField;

        [System.Xml.Serialization.XmlElementAttribute("transaction", Form=System.Xml.Schema.XmlSchemaForm.Unqualified)]
        public object[] transaction {
            get {
                return this.transactionField;
            }
            set {
                this.transactionField = value;
            }
        }

        /// <remarks/>
        [System.Xml.Serialization.XmlAttributeAttribute()]
        public string Prop1 {
            get {
                return this.prop1Field;
            }
            set {
                this.prop1Field = value;
            }
        }

        /// <remarks/>
        [System.Xml.Serialization.XmlAttributeAttribute()]
        public string AccNo {
            get {
                return this.accNoField;
            }
            set {
                this.accNoField = value;
            }
        }
    }
}

However, I want to have an output which preserves the name, and does not append the parent name to the child

eg

public partial class collectionsCollectionCollectionDetails {

Should be output as

public partial class collectionDetails { 

etc

How Do I accomplish this?

Alex
  • 5,674
  • 7
  • 42
  • 65

2 Answers2

0

I´m afraid, as long as you don`t want to change your XSD you would have to implement you own code generation logic to get the expected behavior

DerApe
  • 3,097
  • 2
  • 35
  • 55
0

Your problem can be solved using the solution presented in this post. You have to change your editing style from local (nested) to global. This way, the tool will no longer need to make up names that globally are unique.

Community
  • 1
  • 1
Petru Gardea
  • 21,373
  • 2
  • 50
  • 62