Exemplo n.º 1
0
        /// <summary>
        ///   Parser recursiv de elemente XML.
        /// </summary>
        /// <param name="reader">Cititorul secvenţial care a deschis fişierul XML</param>
        /// <returns>Elementul XML parsat care conţine toate atributele şi subelementele sale</returns>
        private static XMLElement readCurrentElement(XmlTextReader reader)
        {
            if (!reader.IsStartElement()) {

                return null;
            }

            bool hasChildren = !reader.IsEmptyElement;

            XMLElement result = new XMLElement();

            for (int i = 0; i < reader.AttributeCount; ++i) {

                reader.MoveToAttribute(i);
                result.addAttribute(reader.Name, reader.Value);
            }

            if (hasChildren) {

                while (reader.Read() && reader.NodeType != XmlNodeType.EndElement) {

                    if (reader.IsStartElement()) {

                        result.addElement(reader.Name, readCurrentElement(reader));
                    }
                }
            }

            reader.Read();

            return result;
        }
Exemplo n.º 2
0
        /// <summary>
        ///   Adaugă un nou subelement. Nu face nimic dacă există deja.
        /// </summary>
        /// <param name="name">Numele subelementului de adăugat</param>
        /// <param name="element">Elementul propriu zis</param>
        public void addElement(string name, XMLElement element)
        {
            List<XMLElement> list;

            if (containsElements(name)) {

                list = getElements(name);
            }
            else {

                list = new List<XMLElement>();

                this.elements.Add(name, list);
            }

            if (!list.Contains(element)) {

                list.Add(element);
            }
        }