Replace the child nodes and the attributes of an element in CSharp

Description

The following code shows how to replace the child nodes and the attributes of an element.

Example


  /*from ww  w. ja v a2s.c om*/
  
  
   
using System;
using System.Linq;
using System.Xml.Linq;
using System.Collections;
using System.Collections.Generic;


public class MainClass{
   public static void Main(){
        XElement root = new XElement("Root",
            new XElement("Child", "child content")
        );
        
        // ReplaceAll with an XElement object.
        root.ReplaceAll(new XElement("NewChild", "n"));
        Console.WriteLine(root);
        
   }
}




















Home »
  C# Tutorial »
    XML »




Load Parse
Document
Element
Attribute
Namespace
Query
Save
Schema
Style