Mega Code Archive

 
Categories / VB.Net / XML LINQ
 

Returns elements containing this element and all descendant elements

Imports System Imports System.Xml Imports System.Xml.XPath Imports System.Collections Imports System.Collections.Generic Public Class MainClass     Public Shared Sub Main()         Dim xmlTree As XElement = _             <Root Att1="AttributeContent">                 <Child>Some text                     <GrandChild>element content</GrandChild>                 </Child>             </Root>                  Dim das As IEnumerable(Of XElement) = _             From el In xmlTree.DescendantsAndSelf() _             Select el                  For Each el In das             Console.WriteLine(el.Name)         Next     End Sub End Class