Exemplo n.º 1
0
 public static void WriteToXML(XmlWriter xw, PersonInfoPlus pip)
 {
     xw.WriteStartElement("Person");
     xw.WriteAttributeString("ID", pip.ID.ToString());
     xw.WriteElementString("Name", pip.Name);
     xw.WriteElementString("Sexual", Enum.GetName(typeof(SexualEnum), pip.Sexual));
     xw.WriteElementString("Birthday", pip.Birthday.ToShortDateString());
     xw.WriteElementString("Improtance", pip.Improtance.ToString());
     xw.WriteElementString("IconPath", pip.Icon);
     xw.WriteEndElement();
 }
Exemplo n.º 2
0
 public void ReadAllFromFile(string path)
 {
     using (XmlReader xr = XmlReader.Create(path))
     {
         while (xr.Read())
         {
             if (xr.NodeType == XmlNodeType.Element && xr.Name == "PersonInfo")
             {
                 NextID = Convert.ToInt32(xr.GetAttribute("NextID"));
             }
             if (xr.NodeType == XmlNodeType.Element && xr.Name == "Person")
             {
                 XmlReader subElement = xr.ReadSubtree();
                 Persons.Add(PersonInfoPlus.ReadFromXml(subElement));
             }
         }
     }
 }
Exemplo n.º 3
0
        public void WriteAllToFile(string path)
        {
            XmlWriterSettings settings = new XmlWriterSettings();

            settings.Indent = true;
            settings.NewLineOnAttributes = true;
            using (XmlWriter xw = XmlWriter.Create(path, settings))
            {
                xw.WriteStartElement("PersonInfo");
                xw.WriteAttributeString("NextID", NextID.ToString());
                foreach (PersonInfoPlus pip in Persons)
                {
                    PersonInfoPlus.WriteToXML(xw, pip);
                }
                xw.WriteEndElement();
                xw.Flush();
            }
        }