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?
Example:
[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; }
}
Desired Output:
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">
<xs:element name="Person" type="Person" />
<xs:complexType name="Person">
<xs:sequence>
<xs:element minOccurs="0" maxOccurs="1" form="unqualified" name="FirstName" type="xs:string" />
<xs:element minOccurs="0" maxOccurs="1" form="unqualified" name="LastName" type="xs:string" />
<xs:element minOccurs="0" maxOccurs="1" form="unqualified" name="PhoneNo" type="xs:string" />
</xs:sequence>
</xs:complexType>
</xs:schema>
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…