How to retain XML string as a string field during XML deserialization

ZeroCool

New Member
I got an XML input string and want to deserialize it to an object which partially retain the raw XML.\[code\]<SetProfile> <sessionId>A81D83BC-09A0-4E32-B440-0000033D7AAD</sessionId> <profileDataXml> <ArrayOfProfileItem> <ProfileItem> <Name>Pulse</Name> <Value>80</Value> </ProfileItem> <ProfileItem> <Name>BloodPresure</Name> <Value>120</Value> </ProfileItem> </ArrayOfProfileItem> </profileDataXml></SetProfile>\[/code\]The class definition:\[code\]public class SetProfile{ public Guid sessionId; public string profileDataXml;}\[/code\]I hope the deserialization syntax looks like\[code\]string inputXML = "..."; // the above XMLXmlSerializer xs = new XmlSerializer(typeof(SetProfile));using (TextReader reader = new StringReader(inputXML)){ SetProfile obj = (SetProfile)xs.Deserialize(reader); // use obj ....}\[/code\]but XMLSerializer will throw an exception and won't output < profileDataXml >'s descendants to "profileDataXml" field in raw XML string.Is there any way to implement the deserialization like that?
 
Back
Top