title: In C#, how to determine the XSD-defined MaxLength for an element
body: <p>I'm using XmlReader with an attached XSD for validation.</p>
  
  <p>As my XML document is being read and validated, I want to determine in my C# code the 'maxLength' value specified in the XSD for a particular element.  For example, my XSD fragment is very simply defined as:</p>
  
  <pre><code>&lt;xsd:element name="testing" minOccurs="0"&gt;
      &lt;xsd:simpleType&gt;
          &lt;xsd:restriction base="xsd:string"&gt;
              &lt;xsd:maxLength value="10"/&gt;
          &lt;/xsd:restriction&gt;
      &lt;/xsd:simpleType&gt;
  &lt;/xsd:element&gt;
  </code></pre>
  
  <p>I can get the 'minOccurs' value easily using:</p>
  
  <pre><code>myReader.SchemaInfo.SchemaElement.MinOccurs;
  </code></pre>
  
  <p>But how do I get the 'maxLength' value (value of 10 in my example fragment above)???</p>
  
  <p>I thought '<code>myReader.SchemaInfo.SchemaElement.Constraints</code>' might give me this information, but that collection always has a 'Count' of zero.</p>
  
  <p>Thanks,</p>
  
  <p>Pat.</p>