Skips current element and moves to next element. Similar to XmlReader.Skip, but this method also skips even if current node is text node. - CSharp System.Xml

CSharp examples for System.Xml:XML Element

Description

Skips current element and moves to next element. Similar to XmlReader.Skip, but this method also skips even if current node is text node.

Demo Code


using System.Xml;

public class Main{
        /// <summary>
        /// Skips current element and moves to next element. Similar to XmlReader.Skip, but this method also skips even if current node is text node.
        /// </summary>
        /// <param name="reader">XmlReader with current node of element or text of element.</param>
        public static bool MoveToFirstChild(this XmlReader reader)
        {/*from ww  w .  jav a2s.  c  om*/
            if (!reader.IsEmptyElement)
            {
                while (reader.Read())
                {
                    if (reader.NodeType == XmlNodeType.Element)
                        return true;

                    if (reader.NodeType == XmlNodeType.EndElement)
                        break;
                }
            }

            // Read past end element
            reader.Read();

            return false;
        }
}

Related Tutorials