Get sibling elements after this node, in document order in CSharp

Description

The following code shows how to get sibling elements after this node, in document order.

Example


using System;/*from   w w w . j a v a 2s. c  o  m*/
using System.IO;
using System.Xml;
using System.Xml.Linq;
using System.Collections;
using System.Collections.Generic;

public class MainClass{
   public static void Main(){

        XElement xmlTree = new XElement("Root",
            new XText("Text content."),
            new XElement("A1", "A1 content"),
            new XElement("A2", "A2 content"),
            new XElement("A3", "A3 content"),
            new XText("More text content."),
            new XElement("A4", "A4 content"),
            new XElement("A5", "A5 content")
        );
        XElement child = xmlTree.Element("A3");
        IEnumerable<XElement> elements = child.ElementsAfterSelf("A4");
        foreach (XElement el in elements)
            Console.WriteLine(el.Name);
   }
}




















Home »
  C# Tutorial »
    XML »




Load Parse
Document
Element
Attribute
Namespace
Query
Save
Schema
Style