CSharp - Creating an Attribute and Adding It to Its Element

Description

Creating an Attribute and Adding It to Its Element

Demo

using System;
using System.Linq;
using System.Xml.Linq;
using System.Collections.Generic;

class Program//w  w  w. ja  va  2  s .c  om
{
    static void Main(string[] args){
        XElement xBook = new XElement("Book");
        XAttribute xAttribute = new XAttribute("type", "Author");
        xBook.Add(xAttribute);
    
        Console.WriteLine(xBook);
    }
}

Result

Related Topic