Extensions.Nodes(Of T) Method (IEnumerable(Of T))


The .NET API Reference documentation has a new home. Visit the .NET API Browser on docs.microsoft.com to see the new experience.

Returns a collection of the child nodes of every document and element in the source collection.

Namespace:   System.Xml.Linq
Assembly:  System.Xml.Linq (in System.Xml.Linq.dll)

Public Shared Function Nodes(Of T As XContainer) (
	source As IEnumerable(Of T)
) As IEnumerable(Of XNode)


Type: System.Collections.Generic.IEnumerable(Of T)

An IEnumerable(Of T) of XNode that contains the source collection.

Return Value

Type: System.Collections.Generic.IEnumerable(Of XNode)

An IEnumerable(Of T) of XNode of the child nodes of every document and element in the source collection.

Type Parameters


The type of the objects in source, constrained to XContainer.

This method uses deferred execution.

The following example retrieves all of the child nodes for every node in a collection of elements with the name of Child.

                Dim xmlTree As XElement = _

Dim nodes = xmlTree.<Child>.Nodes()

' Note that XNode uses XmlNodeType, which is in the System.Xml namespace.
For Each node As XNode In nodes
    Select Case node.NodeType
        Case XmlNodeType.Element
            Console.WriteLine("Element: {0}", DirectCast(node, XElement).Name)
        Case XmlNodeType.Text
            Console.WriteLine("Text: {0}", DirectCast(node, XText).Value)
    End Select

This example produces the following output:

Text: aaa
Element: GrandChild
Text: bbb
Text: ccc
Element: GrandChild
Text: ddd

Universal Windows Platform
Available since 8
.NET Framework
Available since 3.5
Portable Class Library
Supported in: portable .NET platforms
Available since 2.0
Windows Phone Silverlight
Available since 7.0
Windows Phone
Available since 8.1
Return to top