private static void ReadConfig(string configFile) { if (File.Exists(configFile)) { XmlFileNode root = XmlFileRead.Load(configFile); if (root == null) { return; } if (root.Name == null || root.Name.ToLower() != "configuration") { throw new Exception("Illegal Configuration file: " + configFile); } foreach (XmlFileNode node in root.Nodes) { if (node.Name.ToLower() == "appsettings") { ReadAttributes(node.Nodes, "key", "value"); } if (node.Name.ToLower() == "connectionstrings") { ReadAttributes(node.Nodes, "name", "connectionstring"); } } } }
private static void GetNodes(XmlFile file, XmlFileNode parent) { while (file.Pos < file.MaxPos) { XmlFileNode node = GetNode(file, parent.Name); if (node == null) { break; } parent.Nodes.Add(node); } }
private static XmlFileNode GetNode(XmlFile file, string parentName) { EatComments(file); if (Test(file, "</")) { // End Tag string name = GetElementName(file); if (parentName == null) { throw new Exception("XmlReader: Misplaced end tag - </" + name + ">. Parent was null."); } if (name.ToLower() == parentName.ToLower()) { if (Test(file, '>')) { return(null); } else { throw new Exception("XmlReader: End Tag should end with a >."); } } else { throw new Exception("XmlReader: Misplaced end tag - </" + name + ">"); } } else if (!Test(file, '<')) { throw new Exception("XmlReader: Neither '<' nor '</' found when looking for tag start."); } XmlFileNode node = new XmlFileNode(); node.Name = GetElementName(file); node.Attributes = GetAttributes(file); if (Test(file, "/>")) { } else if (Test(file, '>')) { // Node has not been closed so we need to get subnodes GetNodes(file, node); } return(node); }