Create an XElement from tag name and attribute name and value in CSharp

Description

The following code shows how to create an XElement from tag name and attribute name and value.

Example


    //from  w  w  w.  ja v a2 s.c o m
using System;
using System.Linq;
using System.Xml.Linq;


public class MainClass{
   public static void Main(){
        XElement root;
        
        root = new XElement("Root", new XAttribute("NewAttribute", "n"));
        Console.WriteLine(root);
        
    }
}




















Home »
  C# Tutorial »
    XML »




Load Parse
Document
Element
Attribute
Namespace
Query
Save
Schema
Style