CSharp - Use ToString Method on an Element to get XML Tree in String

Description

Use ToString Method on an Element to get XML Tree in String

Demo

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

class Program/* w  w  w .  ja va 2 s .c  o m*/
{
    static void Main(string[] args){
        XElement name = new XElement("Name", "Joe");
        Console.WriteLine(name.ToString());

        name = new XElement("Person",
          new XElement("FirstName", "Joe"),
          new XElement("LastName", "Ruby"));
        Console.WriteLine(name);
    }
}

Result

Related Topic