Gets the next element of a given XML element, ignoring any non-element nodes Returns either the first valid descendant or the next sibling. - CSharp System.Xml

CSharp examples for System.Xml:XML Element

Description

Gets the next element of a given XML element, ignoring any non-element nodes Returns either the first valid descendant or the next sibling.

Demo Code


using System.Xml.Linq;
using System.Linq;
using System.Collections.Generic;

public class Main{
        /// <summary>
        /// Gets the next element of a given element, ignoring any non-element nodes
        /// Returns either the first valid descendant or the next sibling.
        /// </summary>
        /// <param name="element"></param>
        /// <returns></returns>
        public static XElement NextElement(XElement element)
        {//from w w w  .  ja  v  a2  s .  com
            if (element.Descendants().Count() > 0)
            {
                return element.Descendants().First();
            }

            return NextSibling(element);
        }
}

Related Tutorials