CSharp - Creating Attributes with XAttribute


An attribute implemented via XAttribute class is a name-value pair that is stored in a collection of XAttribute objects belonging to an XElement object.

We can create an attribute and add it to its element on the fly using functional construction.


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

class Program/*from   w  ww  .  j a va  2  s .  c om*/
    static void Main(string[] args){
        XElement xBook = new XElement("Book",new XAttribute("type", "Author"));


Related Topics