Gets the next XML element of a given element, ignoring any non-element nodes - CSharp System.Xml

CSharp examples for System.Xml:XML Element

Description

Gets the next XML element of a given element, ignoring any non-element nodes

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
        /// </summary>
        /// <param name="element"></param>
        /// <returns></returns>
        public static XElement NextSibling(XElement element)
        {//from   w w w.  j a  va 2  s .co m
            XNode siblingNode = element;
            siblingNode = siblingNode.NextNode;

            while (siblingNode != null && siblingNode as XElement == null)
            {
                siblingNode = siblingNode.NextNode;
            }

            return siblingNode as XElement;
        }
}

Related Tutorials