Serialize Property as Xml Attribute in Element

lazygizmo

New Member
I have the following class:\[code\][Serializable]public class SomeModel{ [XmlElement("SomeStringElementName")] public string SomeString { get; set; } [XmlElement("SomeInfoElementName")] public int SomeInfo { get; set; }}\[/code\]Which (when populated with some test data) and Serialized using XmlSerializer.Serialize() results in the following XML:\[code\]<SomeModel> <SomeStringElementName>testData</SomeStringElementName> <SomeInfoElementName>5</SomeInfoElementName></SomeModel>\[/code\]What I need to have is:\[code\]<SomeModel> <SomeStringElementName Value="http://stackoverflow.com/questions/11330643/testData" /> <SomeInfoElementName Value="http://stackoverflow.com/questions/11330643/5" /></SomeModel>\[/code\]Is there a way to specify this as attributes without writing my own custom serialization code?
 
Back
Top