How to Populate XDocument from String in C# ?


This content was proof-read by Grammarly. You can Try Grammary for FREE

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();
        }

    }
    
}
Newsletter Signup

Subscribe to our weekly newsletter below and never miss the latest product or an exclusive offer.

Newsletter Signup

Subscribe to our weekly newsletter below and never miss the latest product or an exclusive offer.

%d bloggers like this: