c# - IXmlSerializable -


Can you help me with a problem with deserialization via IXmlSerializable

 < Code> var ArrayOfAccounts = new accounts (); // This class structure I am trying to read class accounts: list & lt; Session & gt; {} Class Schedule {public datetime startup {get; Set; } Public Date Expired {Received; Set; }} Class session: IXmlSerializable {public string name {get; Set;} public string pass {get; Set;} public list & lt; Scheduled & gt; Schedule = new list & lt; Schedule & gt; (); Public Zero ReadXml (System.Xml.XmlReader Reader) {// and there is a problem here. I do not know how to apply the correct code here. I have tried // code below, but it only works for the first account, and does not restore other schedules. Clear (); XmlReader subR = reader.ReadSubtree (); If (reader.MoveToAttribute ("name")) name = Reader.value; If (reader.MoveToAttribute ("password")) password = reader value; Reader.MoveToContent (); While (subR.ReadToFollowing ("Schedule")) {XmlSerializer x = New XmlSerializer (Typef (Schedule)); Object o = x Dairyialize (Sabr); If (o schedule is) schedules Add (schedule) o); }}  

and the XML itself looks:

  & lt; Accounts & gt; & Lt; Session Username = "18 SRO" Password = "Shalom 99" & gt; & Lt; Schedule & gt; & Lt; StartAt & gt; 0001-01-01T09: 30: 00 & lt; / StartAt & gt; & Lt; EndAt & gt; 0001-01-01T16: 00: 00 & lt; / EndAt & gt; & Lt; / Schedule & gt; & Lt; / Session & gt; & Lt; / Accounting & gt;  

Since you have defined classes, you are only able to use XML serialization. Should be attributes, and use the default XML deserializer.

Your structure does not look very complex, is there any special reason that you are not using the serialization feature instead of deserializing it manually?


Comments

Popular posts from this blog

c++ - Linux and clipboard -

What is expire header and how to achive them in ASP.NET and PHP? -

sql server - How can I determine which of my SQL 2005 statistics are unused? -