XNode.Ancestors Method
Returns a collection of the ancestor elements of this node.
Namespace: System.Xml.Linq
Assembly: System.Xml.Linq (in System.Xml.Linq.dll)
Return Value
Type: System.Collections.Generic.IEnumerable<XElement>An IEnumerable<T> of XElement of the ancestor elements of this node.
The following example uses this method to enumerate the ancestors of a node.
StringBuilder output = new StringBuilder(); XElement xmlTree = new XElement("Root", new XElement("Child", new XElement("GrandChild", "content") ) ); IEnumerable<XElement> grandChild = xmlTree.Descendants("GrandChild"); foreach (XElement el in grandChild.Ancestors()) output.Append(el.Name + Environment.NewLine); OutputTextBlock.Text = output.ToString();
For a list of the operating systems and browsers that are supported by Silverlight, see Supported Operating Systems and Browsers.