Remove attribute from its parent element in CSharp

Description

The following code shows how to remove attribute from its parent element.

Example


using System;//from  w w w  .j a va  2s  . com
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.Remove();
        Console.WriteLine(root);
   }
}




















Home »
  C# Tutorial »
    XML »




Load Parse
Document
Element
Attribute
Namespace
Query
Save
Schema
Style