title: Parsing Xsd for attributes in C#
body: <p>I'm trying to parse a custom XSD to build a list of elements which have custom attributes defined. I've pasted a sample node from my XSD below. In my case, I'm trying to build a list of all elements (simple and complex types) that have been marked as static. Sample -</p>
  
  <pre><code>    &lt;xs:element name="ATestEnum"&gt;
        &lt;xs:annotation&gt;
          &lt;xs:appinfo&gt;
            &lt;ConfigurationMemberMetadata&gt;
              &lt;Static&gt;False&lt;/Static&gt;
            &lt;/ConfigurationMemberMetadata&gt;
          &lt;/xs:appinfo&gt;
        &lt;/xs:annotation&gt;
        &lt;xs:simpleType&gt;
          &lt;xs:restriction base="xs:string"&gt;
            &lt;xs:enumeration value="Sample1" /&gt;
            &lt;xs:enumeration value="Sample2" /&gt;
          &lt;/xs:restriction&gt;
        &lt;/xs:simpleType&gt;
      &lt;/xs:element&gt;
  </code></pre>
  
  <p>I just can't figure out a way to query 'inside' an element for the properties I need. I've gotten as far as this -</p>
  
  <pre><code>var doc = XDocument.Load(schemaFileName);            
  foreach (var element in doc.Descendants(xs + "element"))
  {
      Console.WriteLine(element.Attribute("name").Value);
  }
  </code></pre>
  
  <p>This gives me a list of all the elements in the xsd but not the specific property (ConfigurationMemberMetadata) that I need to check. I see the element.Annotation(type) method but how do I cast it to extract the fields I'm looking for?</p>
  
  <p>I also tried using the XmlTextReader and reading the schema, compiling the schemaset and iterating through the elements but that doesn't help either.</p>
  
  <p>Can someone point me in the right direction? I'm very new to xml parsing and would really appreciate your help! Thanks.</p>