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  ww  . j a v a  2s  . co  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