Пример #1
0
        public void InsertProduct(string id, string name, string price)
        {
            Product p = new Product(id, name, price);

            XmlElement idItem = xml.CreateElement("id");
            XmlElement nameItem = xml.CreateElement("name");
            XmlElement priceItem = xml.CreateElement("price");

            idItem.InnerText = id;
            nameItem.InnerText = name;
            priceItem.InnerText = price;

            XmlElement newItem = xml.CreateElement("product");
            newItem.AppendChild(idItem);
            newItem.AppendChild(nameItem);
            newItem.AppendChild(priceItem);

            xml.Load(xmlPath);
            xml.SelectNodes("/products").Item(0).AppendChild(newItem);
            xml.Save(xmlPath);

            ret.Clear();
            ret = GetProducts();
        }
Пример #2
0
 public List<Product> GetProducts()
 {
     xml.Load(xmlPath);
     XmlNodeList items = xml.SelectNodes("/products/product");
     xml.Save(xmlPath);
     foreach (XmlNode item in items)
     {
         Product p = new Product(item.ChildNodes.Item(0).InnerText,
                                 item.ChildNodes.Item(1).InnerText,
                                 item.ChildNodes.Item(2).InnerText);
         ret.Add(p);
     }
     return ret;
 }