My class structure is as follows.
[Serializable]
[XmlRootAttribute("person", Namespace = "", IsNullable = false)]
public class Person : IDisposable
{
Private int _id;
Private string _name;
[XmlElement(“id”)]
Public int Id
{
Get{ return _id;}
Set{ _id = value;}
}
[XmlElement(“name”)]
Public string Name
{
Get{return _name;}
Set{_name = value;}
}
}
I am getting the following xml when I serialize the above class
<person>
<id>1</id>
<name>Test</name>
</person>
Now, I would like to serialize the above class as follows i.e. I would like append “type” attribute for each public property that is serialized as xml element. I can append “type” attribute to “person” node by declaring another public property “type” with “[XmlAttribute(“type”)]” but I would like to achieve the same for each public property that is serialized as xml element. Any idea to achieve below:
<person type=”Person”>
<id type=”int”>1</id>
<name type=”string”>Test</name>
</person>