Ejemplo n.º 1
0
        public static bool ReadConfig()
        {
            Stack <string> elements = new Stack <string>();

            try
            {
                ClearConfig();

                while (xmlReader.Read())
                {
                    switch (xmlReader.NodeType)
                    {
                    case XmlNodeType.Element:

                        bool isEmptyElement = false;

                        if (!String.IsNullOrEmpty(xmlReader.Name))
                        {
                            elements.Push(xmlReader.Name);
                            isEmptyElement = xmlReader.IsEmptyElement;
                        }

                        if (xmlReader.HasAttributes)
                        {
                            if (xmlReader.MoveToFirstAttribute())
                            {
                                NameValuePair nvpair = new NameValuePair();

                                do
                                {
                                    if (xmlReader.Name == "name")
                                    {
                                        nvpair.Name = xmlReader.Value;
                                    }

                                    if (xmlReader.Name == "value")
                                    {
                                        nvpair.Value = xmlReader.Value;
                                    }
                                }while (xmlReader.MoveToNextAttribute());

                                if (nvpair.IsValid())
                                {
                                    string xmlPath = "";

                                    foreach (string s in elements)
                                    {
                                        xmlPath = s + "/" + xmlPath;
                                    }

                                    nvpair.Name = xmlPath + nvpair.Name;

                                    configNameValuePairs.Add(nvpair);
                                }
                            }
                        }

                        if (isEmptyElement && elements.Count != 0)
                        {
                            elements.Pop();
                        }

                        break;

                    case XmlNodeType.Text:
                        // no need to support text yet
                        break;

                    case XmlNodeType.EndElement:

                        string peek = elements.Peek();

                        if (String.Compare(peek, xmlReader.Name, true) == 0)
                        {
                            elements.Pop();
                        }

                        break;
                    }
                }
            }
            catch //(Exception ex)
            {
                //MessageBox.Show(ex.ToString());
            }

            return(true);
        }