CSharp examples for System.Xml:XML Element
Gets the previous XML element of a given element, ignoring any non-element nodes
using System.Xml.Linq; using System.Linq; using System.Collections.Generic; public class Main{ /// <summary> /// Gets the previous element of a given element, ignoring any non-element nodes /// </summary> /// <param name="element"></param> /// <returns></returns> public static XElement PreviousSibling(XElement element) {//from w ww.j a va 2s .c o m XNode siblingNode = element; siblingNode = siblingNode.PreviousNode; while (siblingNode != null && siblingNode as XElement == null) { siblingNode = siblingNode.PreviousNode; } return siblingNode as XElement; } }