Exemplo n.º 1
0
 public void Store(Article article)
 {
     save(article);
     load();
 }
Exemplo n.º 2
0
        private void save(Article article)
        {
            XmlDocument xdoc = new XmlDocument();
            xdoc.Load(PATH);

            // set root element --> <articles>
            var root = xdoc.DocumentElement;

            // create new elements
            XmlElement xarticle = xdoc.CreateElement("article");
            XmlElement xid = xdoc.CreateElement("id");
            XmlElement xtitle = xdoc.CreateElement("title");
            XmlElement xlink = xdoc.CreateElement("link");

            //get the highest id
            int max = 0;
            foreach (var a in SavedArticles) {
                if (a.ID > max)
                    max = a.ID;
            }

            // get information about the article
            int id = max+1;
            string title = article.Title;
            string link = article.Link;

            // set text inside of the elements
            xid.InnerText = id.ToString();
            xtitle.InnerText = title;
            xlink.InnerText = link;

            // add id, title & link elements to the article element
            xarticle.AppendChild(xid);
            xarticle.AppendChild(xtitle);
            xarticle.AppendChild(xlink);

            // add article to the root element
            root.AppendChild(xarticle);
            xdoc.AppendChild(root);
            xdoc.Save(PATH);
        }