title: How do I programmatically generate an xml schema from a type?
body: <p>I'm trying to generate an xs:schema from any .net Type programmatically.  I know I could use reflection and generate it by iterating over the public properties, but is there a built in way?</p>
  
  <p>Example:</p>
  
  <pre><code>[Serializable]
  public class Person
  {
      [XmlElement(IsNullable = false)] public string FirstName { get; set; }
      [XmlElement(IsNullable = false)] public string LastName { get; set; }
      [XmlElement(IsNullable = true)] public string PhoneNo { get; set; }
  }
  </code></pre>
  
  <p>Desired Output:</p>
  
  <pre><code>&lt;xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"&gt;
    &lt;xs:element name="Person" type="Person" /&gt;
    &lt;xs:complexType name="Person"&gt;
      &lt;xs:sequence&gt;
        &lt;xs:element minOccurs="0" maxOccurs="1" form="unqualified" name="FirstName" type="xs:string" /&gt;
        &lt;xs:element minOccurs="0" maxOccurs="1" form="unqualified" name="LastName" type="xs:string" /&gt;
        &lt;xs:element minOccurs="0" maxOccurs="1" form="unqualified" name="PhoneNo" type="xs:string" /&gt;
      &lt;/xs:sequence&gt;
    &lt;/xs:complexType&gt;
  &lt;/xs:schema&gt;
  </code></pre>