Set the value for attribute in CSharp

Description

The following code shows how to set the value for attribute.

Example


using System;/*w  w w  . jav  a  2s. co m*/
using System.Linq;
using System.Xml;
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", "content1"),
            new XAttribute("Att2", "content2"),
            new XAttribute("Att3", "content3")
        );
        XAttribute att = root.Attribute("Att2");
        att.SetValue("new content");
        Console.WriteLine(root);
   }
}




















Home »
  C# Tutorial »
    XML »




Load Parse
Document
Element
Attribute
Namespace
Query
Save
Schema
Style