Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /* Class ConfUtils servant à créer des fichiers XML
- * +readXML(String path) : ArrayList
- * +writeXML(String path, String data)
- * lang {EN, FR}
- * theme {dark, light}
- * experimental {true, false}
- * mailNotification {true, false}
- */
- using System;
- using System.Collections.Generic;
- using System.Xml;
- namespace ViewModel
- {
- public class ConfUtils
- {
- private Dictionary<string, string> ReadXml(string path)
- {
- var parametersKey = new Dictionary<string, string>();
- var confXml = new XmlDocument();
- confXml.Load(path);
- if (confXml.DocumentElement == null) return parametersKey;
- foreach (XmlNode node in confXml.DocumentElement.ChildNodes)
- {
- parametersKey.Add(node.Name, node.InnerText);
- }
- /* For debug purposes only, write in console what it reads
- foreach (string key in parametersKey.Keys)
- {
- Console.WriteLine("the parameter {0} has for value {1}.", key, parametersKey[key]);
- }*/
- return parametersKey;
- }
- private void WriteXml(string path, string element, string value)
- {
- XmlDocument confXml = new XmlDocument();
- confXml.Load(path);
- if (confXml.DocumentElement == null) return;
- foreach (XmlNode node in confXml.DocumentElement.ChildNodes)
- {
- if (node.Name == element)
- {
- node.InnerText = value;
- }
- }
- confXml.Save(path);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement