Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<pre><code>public class Options { public string UserName { get; set; } public string Password { get; set; } public string DisplayName { get; set; } public string HostAddress { get; set; } public bool SSL { get; set; } public string Port { get; set; } public bool LogEnable { get; set; } public bool GeneralEnable { get; set; } public bool WarningEnable { get; set; } public bool ErrorEnable { get; set; } public static Options Load(string path) { Options options = new Options(); XmlDocument xml = new XmlDocument(); xml.Load(path); XmlNodeReader input = new XmlNodeReader(xml); while (input.Read()) { var elementname = input.Name.ToLower(); switch (elementname) { case "username": options.UserName = input.Value; break; // all other cases case "logenable": options.LogEnable = Boolean.Parse(input.Value); break; // continue with other cases } } } public static void Save(Options options, string path) { XmlTextWriter writer = new XmlTextWriter(path); xmlWriter.WriteStartDocument(true); xmlWriter.WriteStartElement("configuration"); xmlWriter.WriteStartElement("emailConfiguration"); xmlWriter.WriteStartElement("userName"); xmlWriter.WriteString(options.UserName); xmlWriter.WriteEndElemement(); // continue for all elements xmlWriter.WriteEndElement(); xmlWriter.WriteStartElement("logConfiguration"); xmlWriter.WriteStartElement("logEnable"); xmlWriter.WriteString(options.LogEnable.ToString()); xmlWriter.WriteEndElemement(); // continue for all elements xmlWriter.WriteEndElement(); xmlWriter.WriteEndElement(); xmlWriter.Close(); } } </code></pre> <p>I left some work for you to complete ;) Also, I didn't write this is Visual Studio, and I didn't compile it before hand. This code is provided as is with no guarantee or warranty. ;)</p> <p>This is basic XML Read/Write process in .NET, though there are many options. You could use XPath queries, or if you are using .NET 3.5 you could use Linq to Sql which will give you street cred with the cool kids. But the above sample should get you up and running quickly, just promise you'll go do some research on these other things too, you'll be all the better for it.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload