Adds XElement before in CSharp

Description

The following code shows how to adds XElement before.

Example


  //  www .j a  v  a  2 s  .com
  
  
    
using System;
using System.IO;
using System.Xml;
using System.Xml.Linq;
using System.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.AddBeforeSelf(new XElement("NewA", 10));
        Console.WriteLine(xmlTree);
   }
}




















Home »
  C# Tutorial »
    XML »




Load Parse
Document
Element
Attribute
Namespace
Query
Save
Schema
Style