XNode.ElementsBeforeSelf Método

Definição

Retorna uma coleção dos elementos irmãos antes deste nó, por ordem de documento.

Sobrecargas

Name Description
ElementsBeforeSelf()

Retorna uma coleção dos elementos irmãos antes deste nó, por ordem de documento.

ElementsBeforeSelf(XName)

Devolve uma coleção filtrada dos elementos irmãos antes deste nó, por ordem de documento. Apenas os elementos que têm correspondência XName são incluídos na coleção.

Observações

Este método utiliza execução diferida.

ElementsBeforeSelf()

Retorna uma coleção dos elementos irmãos antes deste nó, por ordem de documento.

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)

Devoluções

Um IEnumerable<T> dos XElement elementos irmãos antes deste nó, por ordem de documento.

Exemplos

O exemplo seguinte utiliza este método do eixo.

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

Este exemplo produz a seguinte saída:

Child1
Child2

Observações

Este método inclui apenas irmãos na coleção devolvida. Não inclui descendentes.

Este método utiliza execução diferida.

Ver também

Aplica-se a

ElementsBeforeSelf(XName)

Devolve uma coleção filtrada dos elementos irmãos antes deste nó, por ordem de documento. Apenas os elementos que têm correspondência XName são incluídos na coleção.

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)

Parâmetros

name
XName

O XName para combinar.

Devoluções

Um IEnumerable<T> dos XElement elementos irmãos antes deste nó, por ordem de documento. Apenas os elementos que têm correspondência XName são incluídos na coleção.

Exemplos

O exemplo seguinte utiliza este método.

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

Este exemplo produz a seguinte saída:

Child2

Observações

Este método inclui apenas irmãos na coleção devolvida. Não inclui descendentes.

Este método utiliza execução diferida.

Ver também

Aplica-se a