Пример #1
0
        internal List<Node> Convert()
        {
            Initialize ();

            using (StringReader sr = new StringReader(this.xml))
            {
                using (base.xmlReader = XmlReader.Create(sr))
                {
                    List<Node> nodeCollection = new List<Node>();

                    while (!base.xmlReader.EOF && base.xmlReader.Read())
                    {
                        if (base.IsStartElement())
                        {
                            SetParent ();

                            Node currentNode = CreateNode ();

                            ReadAttributes(currentNode);
                            SetNodeText (currentNode);

                            nodeCollection.Add(currentNode);
                        }
                        else if (base.IsEndElement ())
                        {
                            lastDepth = base.xmlReader.Depth;

                            parent = queue.Pop ().Parent;
                        }
                    }

                    return nodeCollection;
                }
            }
        }
Пример #2
0
        private Node CreateNode()
        {
            Node currentNode = new Node (this.parent);
            this.lastNode = currentNode;
            this.lastDepth = currentNode.Depth = base.xmlReader.Depth;
            currentNode.Name = base.xmlReader.Name;

            return currentNode;
        }
Пример #3
0
        private void ReadAttributes(Node node)
        {
            if (base.xmlReader.HasAttributes)
            {
                node.AttributeCollection = new Dictionary<string, string>();

                for(int i = 0; i < base.xmlReader.AttributeCount; i++)
                {
                    base.xmlReader.MoveToAttribute(i);

                    node.AttributeCollection.Add(base.xmlReader.Name, base.xmlReader.GetAttribute(i));
                }

                base.xmlReader.MoveToElement();
            }
        }
Пример #4
0
        private void Initialize()
        {
            this.queue.Clear ();
            this.queue.Push (root);

            this.parent = null;
            this.lastNode = null;
            this.lastDepth = 0;
        }
Пример #5
0
 private void SetParent()
 {
     if (base.xmlReader.Depth == 0)
     {
         this.parent = this.root;
     }
     else if (lastDepth < base.xmlReader.Depth)
     {
         this.queue.Push (this.lastNode);
         this.parent = this.lastNode;
     }
 }
Пример #6
0
 private void SetNodeText(Node currentNode)
 {
     if (base.xmlReader.HasValue)
     {
         currentNode.Text = base.xmlReader.Value;
     }
 }
Пример #7
0
 internal Node(Node parent)
 {
     this.Parent = parent;
 }