XMLAttribute

    public class Person : IComparable<Person>, IEquatable<Person>
    {
        [XmlAttribute(AttributeName=”Name”)]
        public string Name
        {
            get;
            set;
        }


        [XmlAttribute(AttributeName = “ID”)]
        public int ID
        {
            get;
            set;
        }


        [XmlAttribute(AttributeName = “Phone”)]
        public string Phone
        {
            get;
            set;
        }


        [XmlAttribute(AttributeName = “Address”)]
        public string Address
        {
            get;
            set;
        }


        public Person() : this(“”, 0, “”, “”)
        {
        }


        public Person(string name, int id, string phone, string address)
        {
            this.Name = name;
            this.ID = id;
            this.Phone = phone;
            this.Address = address;
        }


        public Person(Person p)
        {
            this.Name = p.Name;
            this.ID = p.ID;
            this.Phone = p.Phone;
            this.Address = p.Address;
        }


        public virtual void Print()
        {
            Console.WriteLine(“이름: {0} ID: {1} 전화번호: {2} 주소: {3}”, this.Name, this.ID, this.Phone, this.Address);
        }


        // System.Object.ToString method override
        public override string ToString()
        {
            // csv file format으로 출력
            return string.Format(“{0},{1},{2},{3}”, Name, ID, Phone, Address);        
        }
        // 중간생략..
}


<?xml version=”1.0″?>
<ArrayOfPerson xmlns:xsi=”http://www.w3.org/2001/XMLSchema-instance
xmlns:xsd=”http://www.w3.org/2001/XMLSchema“>
  <Person Name=”Park” ID=”1207Phone=”010Address=”단국대” />
  <Person Name=”박똑똑” ID=”5205Phone=”10″ Address=”단국대” />
  <Person Name=”아무개” ID=”1202” Phone=” 041-550-3418” Address=”충남 천안시” />
  <Person Name=”홍군” ID=”1204” Phone=” 041-550-3490” Address=”충남 천안시” />
  <Person Name=”김씨” ID=”5204” Phone=”11” Address=”단국대” />
</ArrayOfPerson>

Leave a Reply

Your email address will not be published. Required fields are marked *