XElement.DescendantsAndSelf Metoda

Definicja

Zwraca kolekcję elementów, które zawierają ten element, oraz wszystkie elementy podrzędne tego elementu w kolejności dokumentu.

Przeciążenia

DescendantsAndSelf(XName)

Zwraca przefiltrowaną kolekcję elementów, które zawierają ten element, oraz wszystkie elementy podrzędne tego elementu w kolejności dokumentu. W kolekcji znajdują się tylko elementy, które mają dopasowanie XName .

DescendantsAndSelf()

Zwraca kolekcję elementów, które zawierają ten element, oraz wszystkie elementy podrzędne tego elementu w kolejności dokumentu.

Uwagi

Ta metoda używa odroczonego wykonania.

DescendantsAndSelf(XName)

Zwraca przefiltrowaną kolekcję elementów, które zawierają ten element, oraz wszystkie elementy podrzędne tego elementu w kolejności dokumentu. W kolekcji znajdują się tylko elementy, które mają dopasowanie XName .

public:
 System::Collections::Generic::IEnumerable<System::Xml::Linq::XElement ^> ^ DescendantsAndSelf(System::Xml::Linq::XName ^ name);
public System.Collections.Generic.IEnumerable<System.Xml.Linq.XElement> DescendantsAndSelf (System.Xml.Linq.XName name);
public System.Collections.Generic.IEnumerable<System.Xml.Linq.XElement> DescendantsAndSelf (System.Xml.Linq.XName? name);
member this.DescendantsAndSelf : System.Xml.Linq.XName -> seq<System.Xml.Linq.XElement>
Public Function DescendantsAndSelf (name As XName) As IEnumerable(Of XElement)

Parametry

name
XName

Element XName do dopasowania.

Zwraca

IEnumerable<XElement>

XElement Element IEnumerable<T> zawierający ten element i wszystkie elementy podrzędne tego elementu w kolejności dokumentu. W kolekcji znajdują się tylko elementy, które mają dopasowanie XName .

Przykłady

Poniższy przykład tworzy drzewo XML, a następnie używa tego elementu .

XElement xmlTree = new XElement("Root",  
    new XAttribute("Att1", "AttributeContent"),  
    new XElement("Child",  
        new XText("Some text"),  
        new XElement("GrandChild", "element content")  
    )  
);  
IEnumerable<XElement> das = xmlTree.DescendantsAndSelf("Child");  
foreach (XElement el in das)  
    Console.WriteLine(el.Name);  
Dim xmlTree As XElement = _  
    <Root Att1="AttributeContent">  
        <Child>Some text  
            <GrandChild>element content</GrandChild>  
        </Child>  
    </Root>  

Dim das As IEnumerable(Of XElement) = xmlTree.DescendantsAndSelf("Child")  

For Each el In das  
    Console.WriteLine(el.Name)  
Next  

Ten przykład generuje następujące wyniki:

Child  

Uwagi

Ta metoda używa odroczonego wykonania.

Zobacz też

Dotyczy

DescendantsAndSelf()

Zwraca kolekcję elementów, które zawierają ten element, oraz wszystkie elementy podrzędne tego elementu w kolejności dokumentu.

public:
 System::Collections::Generic::IEnumerable<System::Xml::Linq::XElement ^> ^ DescendantsAndSelf();
public System.Collections.Generic.IEnumerable<System.Xml.Linq.XElement> DescendantsAndSelf ();
member this.DescendantsAndSelf : unit -> seq<System.Xml.Linq.XElement>
Public Function DescendantsAndSelf () As IEnumerable(Of XElement)

Zwraca

IEnumerable<XElement>

Element IEnumerable<T> z XElement elementami zawierającymi ten element i wszystkie elementy podrzędne tego elementu w kolejności dokumentu.

Przykłady

Poniższy przykład tworzy drzewo XML, a następnie używa tego elementu .

XElement xmlTree = new XElement("Root",  
    new XAttribute("Att1", "AttributeContent"),  
    new XElement("Child",  
        new XText("Some text"),  
        new XElement("GrandChild", "element content")  
    )  
);  
IEnumerable<XElement> das =  
    from el in xmlTree.DescendantsAndSelf()  
    select el;  
foreach (XElement el in das)  
    Console.WriteLine(el.Name);  
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  

Ten przykład generuje następujące wyniki:

Root  
Child  
GrandChild  

Uwagi

Ta metoda używa odroczonego wykonania.

Zobacz też

Dotyczy