Add XElement after in CSharp

Description

The following code shows how to add XElement after.

Example


  //from  w w w  .  j av a 2 s  .  c  om
  
  
    
using System;
using System.IO;
using System.Xml;
using System.Xml.Linq;

public class MainClass{
   public static void Main(){
        XElement xmlTree = new XElement("Root",
            new XElement("A1", 1),
            new XElement("A2", 2),
            new XElement("A3", 3)
        );
        XElement child1 = xmlTree.Element("A1");
        child1.AddAfterSelf(new XElement("NewA", 10));
        Console.WriteLine(xmlTree);
   }
}




















Home »
  C# Tutorial »
    XML »




Load Parse
Document
Element
Attribute
Namespace
Query
Save
Schema
Style