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//from w  w  w .j  a va  2s.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