title: Parsing XSD w/XDocument
body: <p>I am having a heck of a time trying to parse a schema file... was hoping someone could help.</p>
  
  <p>Here is what the xsd looks like</p>
  
  <pre><code> &lt;xs:element name="E1"&gt;
      &lt;xs:complexType&gt;
          &lt;xs:sequence&gt;
              &lt;xs:element name="E2" nillable="true" minOccurs="0"&gt;
                  &lt;xs:complexType&gt;
                      &lt;xs:sequence&gt;
                          &lt;xs:element name="E3" minOccurs="0" maxOccurs="unbounded"&gt;
                              &lt;xs:complexType&gt;
                                  &lt;xs:sequence&gt;
                                      &lt;xs:element name="E4" nillable="true" minOccurs="0"&gt;
                                          &lt;xs:complexType&gt;
                                              &lt;xs:sequence&gt;
                                                  &lt;xs:element name="E5" minOccurs="0" maxOccurs="unbounded"&gt;
                                                      &lt;xs:complexType&gt;
                                                          &lt;xs:attribute name="A1" type="xs:integer" use="optional" /&gt;
                                                          &lt;xs:attribute name="A2" type="xs:string" use="optional" /&gt;
                                                          &lt;xs:attribute name="A3" type="xs:string" use="optional" /&gt;\
                                                      &lt;/xs:complexType&gt;
                                                  &lt;/xs:element&gt;
                                              &lt;/xs:sequence&gt;
                                          &lt;/xs:complexType&gt;
                                      &lt;/xs:element&gt;
                                 &lt;/xs:complexType&gt;
                              &lt;/xs:element&gt;
                           &lt;/xs:complexType&gt;
                       &lt;/xs:element&gt;
  </code></pre>
  
  <p>This isn't complete, but enough to get the idea.  Here is the code I was trying to get the element name, followed by any attributes if they existed, but this is only returning the element names.</p>
  
  <pre><code>var xs = XNamespace.Get("http://www.w3.org/2001/XMLSchema");
  var doc = XDocument.Load(sourceName + sourceApi + "Input.txt");
          foreach (var el in doc.Descendants(xs + "element"))
          {
              Trace.WriteLine("ANDY ------ " + el.Attribute("name").Value);
              foreach (var attr in el.Elements(xs + "attribute"))
              {
                  Trace.WriteLine(attr.Attribute("name").Value);
              }
          }
  </code></pre>
  
  <p>This is outputing</p>
  
  <p>Andy ----- E1
  Andy ----- E2
  Andy ----- E3
  Andy ----- E4
  Andy ----- E5</p>
  
  <p>Where I want it to output</p>
  
  <p>Andy ----- E1
  Andy ----- E2
  Andy ----- E3
  Andy ----- E4
  Andy ----- E5
  A1
  A2
  A3</p>
  
  <p>Thanks in advance.</p>