Replace the attributes of this element with the specified content in CSharp

Description

The following code shows how to replace the attributes of this element with the specified content.

Example


using System;/*  w ww.  j a  v a2  s  .  c  om*/
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 XAttribute("Att1", 1),
            new XAttribute("Att2", 2),
            new XAttribute("Att3", 3)
        );
        root.ReplaceAttributes(
            new XAttribute("NewAtt1", 101)
        );
        Console.WriteLine(root);
   }
}




















Home »
  C# Tutorial »
    XML »




Load Parse
Document
Element
Attribute
Namespace
Query
Save
Schema
Style