Create an Attribute and Adding It to Its Element in CSharp

Description

The following code shows how to create an Attribute and Adding It to Its Element.

Example


using System;/* w  w  w.ja  va 2 s. c  o m*/
using System.Linq;
using System.Collections;
using System.Collections.Generic;
using System.Xml;
using System.Xml.Linq;
public class MainClass {
    public static void Main() {

        XElement xBookParticipant = new XElement("BookParticipant"); 
        XAttribute xAttribute = new XAttribute("type", "Author"); 
        xBookParticipant.Add(xAttribute);
        Console.WriteLine(xBookParticipant);
    }
}




















Home »
  C# Tutorial »
    XML »




Load Parse
Document
Element
Attribute
Namespace
Query
Save
Schema
Style