XNode.ElementsBeforeSelf Metoda

Definicja

Zwraca kolekcję elementów równorzędnych przed tym węzłem w kolejności dokumentu.

Przeciążenia

ElementsBeforeSelf()

Zwraca kolekcję elementów równorzędnych przed tym węzłem w kolejności dokumentu.

ElementsBeforeSelf(XName)

Zwraca filtrowaną kolekcję elementów równorzędnych przed tym węzłem w kolejności dokumentu. W kolekcji znajdują się tylko elementy, które mają dopasowanie XName .

Uwagi

Ta metoda używa odroczonego wykonania.

ElementsBeforeSelf()

Zwraca kolekcję elementów równorzędnych przed tym węzłem w kolejności dokumentu.

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

Zwraca

IEnumerable<XElement>

Element IEnumerable<T> elementów równorzędnych XElement przed tym węzłem w kolejności dokumentu.

Przykłady

W poniższym przykładzie użyto tej metody osi.

XElement xmlTree = new XElement("Root",  
    new XText("Text content."),  
    new XElement("Child1", "child1 content"),  
    new XElement("Child2", "child2 content"),  
    new XElement("Child3", "child3 content"),  
    new XText("More text content."),  
    new XElement("Child4", "child4 content"),  
    new XElement("Child5", "child5 content")  
);  
XElement child = xmlTree.Element("Child3");  
IEnumerable<XElement> elements = child.ElementsBeforeSelf();  
foreach (XElement el in elements)  
    Console.WriteLine(el.Name);  
Dim xmlTree As XElement = _   
        <Root>Text content.  
            <Child1>child1 content</Child1>  
            <Child2>child2 content</Child2>  
            <Child3>child3 content</Child3>More text content.  
            <Child4>child4 content</Child4>  
            <Child5>child5 content</Child5>  
        </Root>  

Dim child As XElement = xmlTree.<Child3>(0)  
Dim elements As IEnumerable(Of XElement) = child.ElementsBeforeSelf()  

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

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

Child1  
Child2  

Uwagi

Ta metoda obejmuje tylko elementy równorzędne w zwróconej kolekcji. Nie zawiera elementów potomnych.

Ta metoda używa odroczonego wykonania.

Zobacz też

Dotyczy

ElementsBeforeSelf(XName)

Zwraca filtrowaną kolekcję elementów równorzędnych przed tym węzłem w kolejności dokumentu. W kolekcji znajdują się tylko elementy, które mają dopasowanie XName .

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

Parametry

name
XName

Element XName do dopasowania.

Zwraca

IEnumerable<XElement>

Element IEnumerable<T> elementów równorzędnych XElement przed tym węzłem w kolejności dokumentu. W kolekcji znajdują się tylko elementy, które mają dopasowanie XName .

Przykłady

W poniższym przykładzie użyto tej metody.

XElement xmlTree = new XElement("Root",  
    new XText("Text content."),  
    new XElement("Child1", "child1 content"),  
    new XElement("Child2", "child2 content"),  
    new XElement("Child3", "child3 content"),  
    new XText("More text content."),  
    new XElement("Child4", "child4 content"),  
    new XElement("Child5", "child5 content")  
);  
XElement child = xmlTree.Element("Child3");  
IEnumerable<XElement> elements = child.ElementsBeforeSelf("Child2");  
foreach (XElement el in elements)  
    Console.WriteLine(el.Name);  
Dim xmlTree As XElement = _   
        <Root>Text content.  
            <Child1>child1 content</Child1>  
            <Child2>child2 content</Child2>  
            <Child3>child3 content</Child3>More text content.  
            <Child4>child4 content</Child4>  
            <Child5>child5 content</Child5>  
        </Root>  

Dim child As XElement = xmlTree.<Child3>(0)  
Dim elements As IEnumerable(Of XElement) = child.ElementsBeforeSelf("Child2")  

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

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

Child2  

Uwagi

Ta metoda obejmuje tylko elementy równorzędne w zwróconej kolekcji. Nie zawiera elementów potomnych.

Ta metoda używa odroczonego wykonania.

Zobacz też

Dotyczy