Compartir vía


Extensions.Nodes<T>(IEnumerable<T>) Método

Definición

Devuelve una colección de los nodos secundarios de todos los documentos y elementos de la colección de origen.

public:
generic <typename T>
 where T : System::Xml::Linq::XContainer[System::Runtime::CompilerServices::Extension]
 static System::Collections::Generic::IEnumerable<System::Xml::Linq::XNode ^> ^ Nodes(System::Collections::Generic::IEnumerable<T> ^ source);
public static System.Collections.Generic.IEnumerable<System.Xml.Linq.XNode> Nodes<T>(this System.Collections.Generic.IEnumerable<T> source) where T : System.Xml.Linq.XContainer;
public static System.Collections.Generic.IEnumerable<System.Xml.Linq.XNode> Nodes<T>(this System.Collections.Generic.IEnumerable<T?> source) where T : System.Xml.Linq.XContainer;
static member Nodes : seq<'T (requires 'T :> System.Xml.Linq.XContainer)> -> seq<System.Xml.Linq.XNode> (requires 'T :> System.Xml.Linq.XContainer)
<Extension()>
Public Function Nodes(Of T As XContainer) (source As IEnumerable(Of T)) As IEnumerable(Of XNode)
<Extension()>
Public Iterator Function Nodes(Of T As XContainer) (source As IEnumerable(Of T)) As IEnumerable(Of XNode)

Parámetros de tipo

T

Tipo de los objetos de source, restringido a XContainer.

Parámetros

source
IEnumerable<T>

Interfaz IEnumerable<T> de XNode que contiene la colección de origen.

Devoluciones

Interfaz IEnumerable<T> de XNode de los nodos secundarios de todos los documentos y elementos de la colección de origen.

Ejemplos

En el ejemplo siguiente se recuperan todos los nodos secundarios de cada nodo de una colección de elementos con el nombre de Child.

XElement xmlTree = XElement.Parse(
    @"<Root><Child>aaa<GrandChild>Text</GrandChild>bbb</Child>" +
    @"<Child>ccc<GrandChild>Text</GrandChild>ddd</Child></Root>");
IEnumerable<XNode> nodes = xmlTree.Elements("Child").Nodes();

foreach (XNode node in nodes)
{
    switch (node.NodeType)
    {
        case XmlNodeType.Element:
            Console.WriteLine("Element: {0}", ((XElement)node).Name);
            break;
        case XmlNodeType.Text:
            Console.WriteLine("Text: {0}", ((XText)node).Value);
            break;
    }
}
Dim xmlTree As XElement = _
    <Root>
        <Child>aaa<GrandChild>Text</GrandChild>bbb</Child>
        <Child>ccc<GrandChild>Text</GrandChild>ddd</Child>
    </Root>

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
Next

Este ejemplo produce el siguiente resultado:

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

Comentarios

Este método usa la ejecución diferida.

Se aplica a

Consulte también