XMLElement & Attribute

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

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

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

    [XmlRoot(“Person”)]
    public class Person : IComparable<Person>, IEquatable<Person>
    {
        [XmlElement(ElementName=”Name”, Order=1)]
        public string Name
        {
            get;
            set;
        }

        [XmlElement(ElementName=”ID”, DataType=”int”, Order=2)]
        public int ID
        {
            get;
            set;
        }

        [XmlElement(ElementName=”Phone”, Order=3)]
        public Phone Phone = new Phone();

        [XmlElement(ElementName=”Address”, Order=4)]
        public string Address
        {
            get;
            set;
        }

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

        // 중간생략
}




<?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 Kyoung Shin</Name>


       <ID>1207</ID>
<Phone WorkPhone=”041-550 HomePhone=”02-379 CellPhone=”010 />




    <Address>서울시</Address>

</Person>


  <Person>



    <Name>박똑똑</Name>


    <ID>5205</ID>


    <Phone WorkPhone=”10 HomePhone=”10 CellPhone=”10 />


    <Address>단국대</Address>

</Person>


<Person>



    <Name>아무개</Name>


    <ID>1202</ID>


      <Phone WorkPhone=”11 HomePhone=”11 CellPhone=”11 /> 
<Address>충남 천안시</Address> 
 </Person>


</ArrayOfPerson>

Leave a Reply

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