How to write and read correctly an xml for this object?

Mil

New Member
I'm trying to create an implementation of this object. Check it out:\[code\]public class ScannedTest : IXmlSerializable{ public string TestName { get;set;} public IList<ImageSource> Images {get;set;} public string[] CorrectAnswers { get; set; } protected override void ReadXml(System.Xml.XmlReader reader) { throw new NotImplementedException(); } protected override void WriteXml(System.Xml.XmlWriter writer) { // Write 'Images' writer.WriteStartElement("Images"); foreach (BitmapImage img in Images) { writer.WriteAttributeString("Image", Utils.ImageToBase64(img)); } writer.WriteEndElement(); // Write 'CorrectAnswers' writer.WriteStartElement("CorrectAnswers"); foreach (string cAnswer in CorrectAnswers) { writer.WriteAttributeString("Value", cAnswer); } writer.WriteEndElement(); }}\[/code\]As you can see, this object just have three properties.I would like to create an object like the next one:\[code\]<Test TestName='...'> <Images> <Image>WJEJKNVFKRKEMKER</Image> <Image>REKREIORJOE5GG3P</Image> </Images> <CorrectAnswers> <Value>3</Value> <Value>B</Value> </CorrectAnswers></Test>\[/code\]Until now, I guess I've implemented well the elements \[code\]Images\[/code\] and \[code\]CorrectAnswers\[/code\]. But I supposed that I'm not creating the root element of my xml.Also, I'd like to know how can I read my Xml, thanks.
 
Back
Top