.NET - Generate class definition from XML

Source XML file

<xml>
   <ToUserName><![CDATA[toUser]]></ToUserName>
   <FromUserName><![CDATA[fromUser]]></FromUserName> 
   <CreateTime>1348831860</CreateTime>
   <MsgType><![CDATA]></MsgType>
   <Content><![CDATA[this is a test]]></Content>
   <MsgId>1234567890123456</MsgId>
   <AgentID>1</AgentID>
</xml>

Generate XSD

$ xsd Msg1.xml
Written file ./Msg1.xsd
<?xml version="1.0" standalone="yes"?>
<xs:schema id="NewDataSet" xmlns="" xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
  <xs:element name="xml">
    <xs:complexType>
      <xs:sequence>
        <xs:element name="ToUserName" type="xs:string" minOccurs="0" />
        <xs:element name="FromUserName" type="xs:string" minOccurs="0" />
        <xs:element name="CreateTime" type="xs:string" minOccurs="0" />
        <xs:element name="MsgType" type="xs:string" minOccurs="0" />
        <xs:element name="Content" type="xs:string" minOccurs="0" />
        <xs:element name="MsgId" type="xs:string" minOccurs="0" />
        <xs:element name="AgentID" type="xs:string" minOccurs="0" />
      </xs:sequence>
    </xs:complexType>
  </xs:element>
  <xs:element name="NewDataSet" msdata:IsDataSet="true" msdata:UseCurrentLocale="true">
    <xs:complexType>
      <xs:choice minOccurs="0" maxOccurs="unbounded">
        <xs:element ref="xml" />
      </xs:choice>
    </xs:complexType>
  </xs:element>
</xs:schema>

Generate Class

$ xsd Msg1.xsd /c
Written file ./Msg1.cs
//------------------------------------------------------------------------------

// <auto-generated>

//     This code was generated by a tool.

//     Runtime Version:4.0.30319.42000

//

//     Changes to this file may cause incorrect behavior and will be lost if

//     the code is regenerated.

// </auto-generated>

//------------------------------------------------------------------------------

 
// 

//This source code was auto-generated by MonoXSD

//

namespace Schemas {
    /// <remarks/>

    [System.CodeDom.Compiler.GeneratedCodeAttribute("xsd", "0.0.0.0")]
    [System.SerializableAttribute()]
    [System.Diagnostics.DebuggerStepThroughAttribute()]
    [System.ComponentModel.DesignerCategoryAttribute("code")]
    [System.Xml.Serialization.XmlTypeAttribute(AnonymousType=true)]
    [System.Xml.Serialization.XmlRootAttribute(Namespace="", IsNullable=false)]
    public partial class xml {
         
        private string toUserNameField;
         
        private string fromUserNameField;
         
        private string createTimeField;
         
        private string msgTypeField;
         
        private string contentField;
         
        private string msgIdField;
         
        private string agentIDField;
         
        /// <remarks/>

        [System.Xml.Serialization.XmlElementAttribute(Form=System.Xml.Schema.XmlSchemaForm.Unqualified)]
        public string ToUserName {
            get {
                return this.toUserNameField;
            }
            set {
                this.toUserNameField = value;
            }
        }
         
        /// <remarks/>

        [System.Xml.Serialization.XmlElementAttribute(Form=System.Xml.Schema.XmlSchemaForm.Unqualified)]
        public string FromUserName {
            get {
                return this.fromUserNameField;
            }
            set {
                this.fromUserNameField = value;
            }
        }
         
        /// <remarks/>

        [System.Xml.Serialization.XmlElementAttribute(Form=System.Xml.Schema.XmlSchemaForm.Unqualified)]
        public string CreateTime {
            get {
                return this.createTimeField;
            }
            set {
                this.createTimeField = value;
            }
        }
         
        /// <remarks/>

        [System.Xml.Serialization.XmlElementAttribute(Form=System.Xml.Schema.XmlSchemaForm.Unqualified)]
        public string MsgType {
            get {
                return this.msgTypeField;
            }
            set {
                this.msgTypeField = value;
            }
        }
         
        /// <remarks/>

        [System.Xml.Serialization.XmlElementAttribute(Form=System.Xml.Schema.XmlSchemaForm.Unqualified)]
        public string Content {
            get {
                return this.contentField;
            }
            set {
                this.contentField = value;
            }
        }
         
        /// <remarks/>

        [System.Xml.Serialization.XmlElementAttribute(Form=System.Xml.Schema.XmlSchemaForm.Unqualified)]
        public string MsgId {
            get {
                return this.msgIdField;
            }
            set {
                this.msgIdField = value;
            }
        }
         
        /// <remarks/>

        [System.Xml.Serialization.XmlElementAttribute(Form=System.Xml.Schema.XmlSchemaForm.Unqualified)]
        public string AgentID {
            get {
                return this.agentIDField;
            }
            set {
                this.agentIDField = value;
            }
        }
    }
     
    /// <remarks/>

    [System.CodeDom.Compiler.GeneratedCodeAttribute("xsd", "0.0.0.0")]
    [System.SerializableAttribute()]
    [System.Diagnostics.DebuggerStepThroughAttribute()]
    [System.ComponentModel.DesignerCategoryAttribute("code")]
    [System.Xml.Serialization.XmlTypeAttribute(AnonymousType=true)]
    [System.Xml.Serialization.XmlRootAttribute(Namespace="", IsNullable=false)]
    public partial class NewDataSet {
         
        private xml[] itemsField;
         
        /// <remarks/>

        [System.Xml.Serialization.XmlElementAttribute("xml")]
        public xml[] Items {
            get {
                return this.itemsField;
            }
            set {
                this.itemsField = value;
            }
        }
    }
}