title: How to parse an xsd file which has nested elements(complexType and simpleType elements and attributes)?
body: <p>I have an xsd file like that:</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="utf-8" ?&gt;
  &lt;xs:schema attributeFormDefault="unqualified" elementFormDefault="qualified" xmlns:xs="http://www.w3.org/2001/XMLSchema"&gt;
      &lt;xs:element name="transfer"&gt;
          &lt;xs:complexType&gt;
              &lt;xs:sequence&gt;
                  &lt;xs:element name="sourceGLN" type="xs:string" minOccurs="1" maxOccurs="1" /&gt;
                  &lt;xs:element name="destinationGLN" type="xs:string" minOccurs="1" maxOccurs="1" /&gt;
                  &lt;xs:element name="actionType" minOccurs="1" maxOccurs="1"&gt;
                      &lt;xs:simpleType&gt;
                          &lt;xs:restriction base="xs:string"&gt;
                              &lt;xs:enumeration value="P" /&gt; &lt;!-- Mal Alim (Purchase) --&gt;
                              &lt;xs:enumeration value="S" /&gt; &lt;!-- Satis (Sale) --&gt;
                              &lt;xs:enumeration value="C" /&gt; &lt;!-- Cancel Sale (Cancel) --&gt;
                              &lt;xs:enumeration value="R" /&gt; &lt;!-- Iade (Return) --&gt;
                              &lt;xs:enumeration value="D" /&gt; &lt;!-- Deaktivasyon (Deactivation) --&gt;
                              &lt;xs:enumeration value="M" /&gt; &lt;!-- Uretim (Manufacture) --&gt;
                              &lt;xs:enumeration value="I" /&gt; &lt;!-- Ithalat (Import) --&gt;
                              &lt;xs:enumeration value="X" /&gt; &lt;!-- Ihrac (eXport) --&gt;
                              &lt;xs:enumeration value="O" /&gt; &lt;!-- Sarf (cOnsume) --&gt;
                              &lt;xs:enumeration value="N" /&gt; &lt;!-- Bilgi (iNformation) --&gt;
                              &lt;xs:enumeration value="T" /&gt; &lt;!-- Devir (Transfer) --&gt;
                              &lt;xs:enumeration value="L" /&gt; &lt;!-- Devir Iptal (canceL Transfer) --&gt;
                              &lt;xs:enumeration value="F" /&gt; &lt;!-- Aktarim (non-its transFer) --&gt;
                              &lt;xs:enumeration value="K" /&gt; &lt;!-- Aktarim Iptal (non-its cancel transfer) --&gt;
                          &lt;/xs:restriction&gt;
                      &lt;/xs:simpleType&gt;
                  &lt;/xs:element&gt;
                  &lt;xs:element name="shipTo" type="xs:string" minOccurs="0" maxOccurs="1" /&gt;
                  &lt;xs:element name="documentNumber" type="xs:string" minOccurs="0" maxOccurs="1" /&gt;
                  &lt;xs:element name="documentDate" type="xs:date" minOccurs="0" maxOccurs="1" /&gt;
                  &lt;xs:element name="note" type="xs:string" minOccurs="0" maxOccurs="1" /&gt;
                  &lt;xs:element name="version" type="xs:string" minOccurs="0" maxOccurs="1" /&gt;
                  &lt;xs:element name="carrier" type="carrierType" minOccurs="1" maxOccurs="unbounded" /&gt;
              &lt;/xs:sequence&gt;
          &lt;/xs:complexType&gt;
      &lt;/xs:element&gt;
      &lt;xs:complexType name="carrierType"&gt;
          &lt;xs:sequence minOccurs="1" maxOccurs="unbounded"&gt;
              &lt;xs:choice minOccurs="1" maxOccurs="1"&gt;
                  &lt;xs:element name="productList" type="productListType" minOccurs="1" maxOccurs="1" /&gt;
                  &lt;xs:element name="carrier" type="carrierType" minOccurs="1" maxOccurs="1" /&gt;
              &lt;/xs:choice&gt;
          &lt;/xs:sequence&gt;
          &lt;xs:attribute name="carrierLabel" use="required"&gt;
              &lt;xs:simpleType&gt;
                  &lt;xs:restriction base="xs:string"&gt;
                      &lt;xs:length value="20" /&gt;
                  &lt;/xs:restriction&gt;
              &lt;/xs:simpleType&gt;
          &lt;/xs:attribute&gt;
          &lt;xs:attribute name="containerType" type="xs:string" use="optional" /&gt;
      &lt;/xs:complexType&gt;
      &lt;xs:complexType name="productListType"&gt;
          &lt;xs:sequence&gt;
              &lt;xs:element name="serialNumber" type="xs:string" minOccurs="1" maxOccurs="unbounded" /&gt;
          &lt;/xs:sequence&gt;
          &lt;xs:attribute name="GTIN" type="xs:string" use="required" /&gt;
          &lt;xs:attribute name="lotNumber" type="xs:string" use="required" /&gt;
          &lt;xs:attribute name="productionDate" type="xs:date" use="optional" /&gt;
          &lt;xs:attribute name="expirationDate" type="xs:date" use="required" /&gt;
          &lt;xs:attribute name="PONumber" type="xs:string" use="optional" /&gt;
      &lt;/xs:complexType&gt;
  &lt;/xs:schema&gt;
  </code></pre>
  
  <p>And I have code Like that:</p>
  
  <pre><code>using System;
  using System.Collections;
  using System.Xml;
  using System.Xml.Schema;
  
  namespace ConsoleApplication1
  {
      class XmlSchemaTraverseExample
      {
          static void Main()
          {
              // Add the customer schema to a new XmlSchemaSet and compile it.
              // Any schema validation warnings and errors encountered reading or 
              // compiling the schema are handled by the ValidationEventHandler delegate.
              XmlSchemaSet schemaSet = new XmlSchemaSet();
              schemaSet.ValidationEventHandler += new ValidationEventHandler(ValidationCallback);
              schemaSet.Add("http://www.w3.org/2001/XMLSchema", "C:\\Users\\ahmet.ulusoy\\Desktop\\pts_xml_schema_v_1_4.xsd");
              schemaSet.Compile();
  
              // Retrieve the compiled XmlSchema object from the XmlSchemaSet
              // by iterating over the Schemas property.
              XmlSchema customerSchema = null;
              foreach (XmlSchema schema in schemaSet.Schemas())
              {
                  customerSchema = schema;
              }
  
              // Iterate over each XmlSchemaElement in the Values collection
              // of the Elements property.
              foreach (XmlSchemaElement element in customerSchema.Elements.Values)
              {
  
                  Console.WriteLine("Element: {0}", element.Name);
  
                  // Get the complex type of the Customer element.
                  XmlSchemaComplexType complexType = element.ElementSchemaType as XmlSchemaComplexType;
  
                  // If the complex type has any attributes, get an enumerator 
                  // and write each attribute name to the console.
                  if (complexType.AttributeUses.Count &gt; 0)
                  {
                      IDictionaryEnumerator enumerator =
                          complexType.AttributeUses.GetEnumerator();
  
                      while (enumerator.MoveNext())
                      {
                          XmlSchemaAttribute attribute =
                              (XmlSchemaAttribute)enumerator.Value;
  
                          Console.WriteLine("Attribute: {0}", attribute.Name);
                      }
                  }
  
                  // Get the sequence particle of the complex type.
                  XmlSchemaSequence sequence = complexType.ContentTypeParticle as XmlSchemaSequence;
  
                  // Iterate over each XmlSchemaElement in the Items collection.
                  foreach (   XmlSchemaElement childElement in sequence.Items)
                  {
                      Console.WriteLine("Element: {0}", childElement.Name);
                  }
              }
          }
  
          static void ValidationCallback(object sender, ValidationEventArgs args)
          {
              if (args.Severity == XmlSeverityType.Warning)
                  Console.Write("WARNING: ");
              else if (args.Severity == XmlSeverityType.Error)
                  Console.Write("ERROR: ");
  
              Console.WriteLine(args.Message);
          }
      }
  }
  </code></pre>
  
  <p>When I tried to run it gives me the just first element' elements name.
  After that how can I take other two xs:complexType name="carrierType" and xs:complexType name="productListType" and their sub elements and attributes?</p>
  
  <p>I made this part and gonna update the code.</p>
  
  <p>I also want to make a generic class with these data and data types. What do I should?</p>
  
  <p>Thank you for your advance.</p>