title: Traversing XML Schemas failed
body: <p>I want to parse all information/elements from a xml schema (xsd) and working with them as variables in my program. I found this article from microsoft: <a href="http://msdn.microsoft.com/en-us/library/ms255932.aspx" rel="nofollow">http://msdn.microsoft.com/en-us/library/ms255932.aspx</a></p>
  
  <p><strong>Code example from Microsoft</strong></p>
  
  <pre><code>using System;
  using System.Collections;
  using System.Xml;
  using System.Xml.Schema;
  
  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.tempuri.org", "customer.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><strong>XML Schema:</strong></p>
  
  <pre><code>&lt;?xml version="1.0"?&gt;
  &lt;xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"&gt;
      &lt;xs:element name="network" type="netType"/&gt;
      &lt;xs:complexType name="netType"&gt;
          &lt;xs:sequence&gt;
              &lt;xs:element name="Version"&gt;
                  &lt;xs:complexType&gt;
                      &lt;xs:sequence&gt;
                          &lt;xs:element name="Min" type="xs:int"/&gt;
                          &lt;xs:element name="Max" type="xs:int"/&gt;
                      &lt;/xs:sequence&gt;
                  &lt;/xs:complexType&gt;
              &lt;/xs:element&gt;
              &lt;xs:element name="File"&gt;
                  &lt;xs:complexType&gt;
                      &lt;xs:sequence&gt;
                          &lt;xs:element name="Min" type="xs:int"/&gt;
                          &lt;xs:element name="Max" type="xs:int"/&gt;
                      &lt;/xs:sequence&gt;
                  &lt;/xs:complexType&gt;
              &lt;/xs:element&gt;
              &lt;xs:element name="NW"&gt;
                  &lt;xs:complexType&gt;
                      &lt;xs:sequence&gt;
                          &lt;xs:element name="Ethernet"&gt;
                              &lt;xs:complexType&gt;
                                  &lt;xs:sequence&gt;
                                      &lt;xs:element name="Cons"&gt;
                                          &lt;xs:simpleType&gt;
                                              &lt;xs:list itemType="xs:int"/&gt;
                                          &lt;/xs:simpleType&gt;
                                      &lt;/xs:element&gt;
                                  &lt;/xs:sequence&gt;
                              &lt;/xs:complexType&gt;
                          &lt;/xs:element&gt;
                          &lt;xs:element name="Mail"/&gt;
                      &lt;/xs:sequence&gt;
                  &lt;/xs:complexType&gt;
              &lt;/xs:element&gt;
          &lt;/xs:sequence&gt;
      &lt;/xs:complexType&gt;
  &lt;/xs:schema&gt;
  </code></pre>
  
  <hr>
  
  <p>The program runs without errors, but I get only the elements in the first tree. Example:</p>
  
  <p><strong>Output:</strong></p>
  
  <pre><code>Element: Version
  Element: File
  </code></pre>
  
  <p>But I want all elements: Min, Max from Version and Min, Max from File like:</p>
  
  <p><strong>What I need:</strong></p>
  
  <pre><code>Element: Version
  Element: Min
  Element: Max
  Element: File
  Element: Min
  Element: Max
  </code></pre>
  
  <p><strong>So my questions:</strong></p>
  
  <ul>
  <li>How can I get all elements?</li>
  <li>And can I use the elements in my program like: Version.Min = 5.4</li>
  </ul>