How to Populate XDocument from String in C# ?

To populate the XDocument from a string in C# , we can use the Parse method defined in the XDocument class.

Below is a sample code snippet that demonstrates how to populate XDocument from string in C#.

How to Populate XDocument from String in C# ?

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

namespace AbundantcodeConsoleApp
{
    class Program
    {
        static void Main(string[] args)
        {

            string xmlString = @"<?xml version=""1.0""?><Employee><Name>Abundantcode</Name></Employee>";
            XDocument document = XDocument.Parse(xmlString);
            Console.WriteLine(document);
            Console.ReadLine();
        }

    }
    
}
%d