CSharp - Creating XElement from String value


Creating XElement from String value


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

class Program//from w  w w  .  j  ava  2  s.c o  m
    static void Main(string[] args){
        XElement xBook = new XElement("Book");


In the example, we instantiate an XElement object by passing the element's name as a string.

An XName object is created for us with a LocalName of Book and is assigned to the XElement object's Name property.

In this case, no namespace is provided, so the XName object has no namespace.

Related Topic