Check if current node appears after a specified node in terms of document order in CSharp

Description

The following code shows how to check if current node appears after a specified node in terms of document order.

Example


  // w w w . j a v a 2 s  .co m
  
  
    
using System;
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 child3 = xmlTree.Element("A3");
        XElement child5 = xmlTree.Element("A5");
        if (child5.IsAfter(child3))
            Console.WriteLine("A5 is after A3");
        else
            Console.WriteLine("A5 is not after A3");
   }
}

The code above generates the following result.





















Home »
  C# Tutorial »
    XML »




Load Parse
Document
Element
Attribute
Namespace
Query
Save
Schema
Style