Пример #1
0
        // reads the next thing in the document, xText and endElement are also included, but not attributes
        private void ReadNext()
        {
            if (LastNode.Type == XmlNodeType.Attribute) // attributs are not supposed to be read by Read()
            {
                RemoveLastNode();
            }

            if (LastNode.Type == XmlNodeType.EndElement) // we remove the endElement, to avoid reread it, then we find the next element
            {
                RemoveLastNode();
                ToNextSiblingOrPreviousNode();
            }
            else
            {
                INTERNAL_NodeType node = GetNode(LastChildList);

                if (node.Type == XmlNodeType.None)// no more child, we return to the previous node
                {
                    if (_nodeStack.Count > 0)
                    {
                        if (LastNode.Type == XmlNodeType.Element && !IsEmptyElement) // we now read the endElement of the LastNode element
                        {
                            AddNewNode(new INTERNAL_NodeType(LastNode, XmlNodeType.EndElement));
                        }
                        else
                        {
                            ToNextSiblingOrPreviousNode();
                        }
                    }
                    else
                    {
                        return; // end of document
                    }
                }
                else
                {
                    AddNewNode(node);
                }
            }
        }
Пример #2
0
        // we try to read the next sibling if it exists, otherwise we return to the previous node
        private bool ToNextSiblingOrPreviousNode()
        {
            RemoveLastNode();
            if (MoveToNextNode()) // condition equivalent to stack count > 0
            {
                INTERNAL_NodeType node = GetNode(LastChildList);

                if (node.Type != XmlNodeType.None) // find a sibling
                {
                    AddNewNode(node);
                    return(true);
                }
                else if (LastNode.Type == XmlNodeType.Element)// find an end element
                {
                    AddNewNode(new INTERNAL_NodeType(LastNode, XmlNodeType.EndElement));
                    return(true);
                }
                // otherwise, it means the end of another container than element, typically the end of XDocument
            }

            return(false); // end of the document
        }
Пример #3
0
 private void AddNewNode(INTERNAL_NodeType node)
 {
     _nodeStack.Add(node);
 }