XElement.DescendantNodesAndSelf Method
[ This article is for Windows Phone 8 developers. If you’re developing for Windows 10, see the latest documentation. ]
Returns a collection of nodes that contain this element, and all descendant nodes of this element, in document order.
Assembly: System.Xml.Linq (in System.Xml.Linq.dll)
Return Value
Type: System.Collections.Generic.IEnumerable<XNode>An IEnumerable<T> of XNode that contain this element, and all descendant nodes of this element, in document order.
The following example creates an XML tree, and then uses this axis method.
StringBuilder output = new StringBuilder(); XElement xmlTree = new XElement("Root", // Attributes are not nodes, so will not be returned by DescendantNodesAndSelf. new XAttribute("Att1", "AttributeContent"), new XElement("Child", new XText("Some text"), new XElement("GrandChild", "element content") ) ); IEnumerable<XNode> dnas = from node in xmlTree.DescendantNodesAndSelf() select node; foreach (XNode node in dnas) { if (node is XElement) output.Append((node as XElement).Name + Environment.NewLine); else output.Append(node + Environment.NewLine); } OutputTextBlock.Text = output.ToString();
Show: