示例#1
0
        /// <summary>
        /// Loads the xml configuration from a file
        /// </summary>
        /// <param name="configFile">The config file</param>
        /// <returns>The parsed config</returns>
        public static XMLConfigFile ParseXMLFile(FileInfo configFile)
        {
            XMLConfigFile root = new XMLConfigFile(null);

            if (!configFile.Exists)
            {
                return(root);
            }

            ConfigElement current = root;
            XmlTextReader reader  = new XmlTextReader(configFile.OpenRead());

            while (reader.Read())
            {
                if (reader.NodeType == XmlNodeType.Element)
                {
                    if (reader.Name == "root")
                    {
                        continue;
                    }

                    if (reader.Name == "param")
                    {
                        string name = reader.GetAttribute("name");
                        if (name != null && name != "root")
                        {
                            ConfigElement newElement = new ConfigElement(current);
                            current[name] = newElement;
                            current       = newElement;
                        }
                    }
                    else
                    {
                        ConfigElement newElement = new ConfigElement(current);
                        current[reader.Name] = newElement;
                        current = newElement;
                    }
                }
                else if (reader.NodeType == XmlNodeType.Text)
                {
                    current.Set(reader.Value);
                }
                else if (reader.NodeType == XmlNodeType.EndElement)
                {
                    if (reader.Name != "root")
                    {
                        current = current.Parent;
                    }
                }
            }
            reader.Close();
            return(root);
        }
示例#2
0
        public static XMLConfigFile ParseXMLFile(FileInfo configFile)
        {
            XMLConfigFile xMLConfigFile = new XMLConfigFile(null);

            if (!configFile.Exists)
            {
                return(xMLConfigFile);
            }
            ConfigElement configElement = xMLConfigFile;
            XmlTextReader xmlTextReader = new XmlTextReader(configFile.OpenRead());

            while (xmlTextReader.Read())
            {
                if (xmlTextReader.NodeType == XmlNodeType.Element)
                {
                    if (!(xmlTextReader.Name == "root"))
                    {
                        if (xmlTextReader.Name == "param")
                        {
                            string attribute = xmlTextReader.GetAttribute("name");
                            if (attribute != null && attribute != "root")
                            {
                                ConfigElement configElement2 = new ConfigElement(configElement);
                                configElement[attribute] = configElement2;
                                configElement            = configElement2;
                            }
                        }
                        else
                        {
                            ConfigElement configElement3 = new ConfigElement(configElement);
                            configElement[xmlTextReader.Name] = configElement3;
                            configElement = configElement3;
                        }
                    }
                }
                else
                {
                    if (xmlTextReader.NodeType == XmlNodeType.Text)
                    {
                        configElement.Set(xmlTextReader.Value);
                    }
                    else
                    {
                        if (xmlTextReader.NodeType == XmlNodeType.EndElement && xmlTextReader.Name != "root")
                        {
                            configElement = configElement.Parent;
                        }
                    }
                }
            }
            xmlTextReader.Close();
            return(xMLConfigFile);
        }
示例#3
0
        public static XMLConfigFile ParseXMLFile(FileInfo configFile)
        {
            XMLConfigFile file = new XMLConfigFile(null);

            if (configFile.Exists)
            {
                ConfigElement parent = file;
                XmlTextReader reader = new XmlTextReader(configFile.OpenRead());
                while (reader.Read())
                {
                    if (reader.NodeType == XmlNodeType.Element)
                    {
                        if (reader.Name != "root")
                        {
                            if (reader.Name == "param")
                            {
                                string attribute = reader.GetAttribute("name");
                                if ((attribute != null) && (attribute != "root"))
                                {
                                    ConfigElement element2 = new ConfigElement(parent);
                                    parent[attribute] = element2;
                                    parent            = element2;
                                }
                            }
                            else
                            {
                                ConfigElement element3 = new ConfigElement(parent);
                                parent[reader.Name] = element3;
                                parent = element3;
                            }
                        }
                    }
                    else if (reader.NodeType == XmlNodeType.Text)
                    {
                        parent.Set(reader.Value);
                    }
                    else if ((reader.NodeType == XmlNodeType.EndElement) && (reader.Name != "root"))
                    {
                        parent = parent.Parent;
                    }
                }
                reader.Close();
            }
            return(file);
        }