Exemple #1
0
        void LoadMessages(string fileName)
        {
            try
            {
                XDocument doc = XDocument.Load(fileName);

                messages.Clear();
                MyMessage msg;

                foreach (XElement el in doc.Root.Elements())
                {
                    msg = new MyMessage();

                    foreach (XElement child in el.Elements())
                    {
                        if (child.Name == "text")
                        {
                            msg.Text = child.Value;
                        }
                        else if (child.Name == "datestr")
                        {
                            msg.DateStr = child.Value;
                        }
                    }

                    foreach (XAttribute attr in el.Attributes())
                    {
                        if (attr.Name == "date")
                        {
                            msg.Date = DateTime.Parse(attr.Value);
                        }
                    }

                    messages.Enqueue(msg);

                }

            }
            catch (Exception ex)
            {
                PrintError(ex);
            }
        }